Notifications
Clear all

[Closed] dotNet UI

I’m going to be building my first complete dotNet ui in maxscript and I wanted to started a post here on cgtalk show the process from start to finish on building the UI.

A few reasons for doing so is…

  1. I’m not familiar with dotNet and a lot of people seem intimidated by it, so hopefully in this thread people will be able to pick up an learn things from it which will allow them and hopefully make them want to use dotNet. It has a ton more functionality than that of maxscript and it is also a lot more customizable.

  2. With me not knowing dotNet very well, I’ll be sure to have a handful of questions on how to achieve and build the UI i’m after.

With all that in mind here we go.

I’ve attached and image of the UI I’m trying to build stage 1.
There are 3 buttons at the top and if you click on button 1 it then displays a row of, predefined vertically aligned buttons.
If the user clicks on button 2 it does the same thing, hiding all the buttons related to button 1 and then displaying the ones related to group 2.
This part of the UI I’m not sure how to do.

In maxscript I would do a simple visible property on the buttons and just hide and unhide them as needed.

Here is the start of my code so far.
Thanks

John Martini


--Create a form and display it in Max. 
--Read about this process in the form & MaxForm tutorial. 
form=dotNetObject "form"
sysPointer=dotNetObject "system.intPtr" (windows.getMaxHWND())
maxHandle=dotNetObject "maxCustomControls.win32HandleWrapper" sysPointer
form.show maxHandle
form.bounds=dotNetObject "system.drawing.rectangle" 10 90 400 400
form.text="DotNet UI" 
	

btn1 = dotNetObject "system.windows.forms.button" 
btn1.bounds=dotNetObject "System.drawing.rectangle" 10 10 36 36
btn1.flatStyle=btn1.flatStyle.flat
btn1.backColor=btn1.backColor.darkRed
btn1.text="1"
	
btn2 = dotNetObject "system.windows.forms.button" height:50
btn2.bounds=dotNetObject "System.drawing.rectangle" 48 10 36 36
btn2.flatStyle=btn2.flatStyle.flat
btn2.backColor=btn2.backColor.darkGreen
btn2.text="2"
	
btn3 = dotNetObject "system.windows.forms.button"
btn3.bounds=dotNetObject "System.drawing.rectangle" 86 10 36 36
btn3.flatStyle=btn3.flatStyle.flat
btn3.backColor=btn3.backColor.darkBlue
btn3.text="3"
	
--Add the pictureBox to the form
form.controls.add btn1
form.controls.add btn2
form.controls.add btn3

220 Replies
1 Reply
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

You can do the same thing with dotnet, all the controls have a .visible property.

Hey Lo thanks for the response.
Is there an easy way to actually rotate the buttons like in the image. So they are sideways.

Aside from that is there a subrollout or the equivelant of that I should put the groups of buttons in. That way if to many get added it will be able to scroll.

 lo1

the easy way is to make bitmaps and use those instead of text.
The hard way is to use custom paint using GDI, but I’d go with the easy way in this case.

There is no control I know that looks like a 3dsmax subrollout, but any controls that inherits from scrollablecontrol (for example, the Panel control) can host other controls and automatically show a scrollbar if they are not in the visible range.

For learning dotnet, it is a good idea to familiarize yourself with the msdn dotnet library, it’s a very useful resource:
http://msdn.microsoft.com/en-us/library/system.windows.forms.aspx

Hey John,

Nice idea creating a post about your experience with dotNet.

Firstly, instead of using a standard dotNet form, you’ll probably want to use a maxForm. This will give you the max icon in the top left of the window, automatically minimise the window when the main max window is minimised, and tie in a bit closer to 3ds max

Use this for your form:

form=dotNetObject "MaxCustomControls.MaxForm"

Also, this may be basic, but it really does help when trying to find out about the possibilities of a dotNet control:


form = dotNetObject "MaxCustomControls.MaxForm"
showProperties form --Shows all properties of maxform
showMethods form --Shows all methods of maxform
showEvents form --Shows all events of maxform

Tim

Maybe you have a reason to do it all in maxscript, but I can’t help but wonder why you wouldn’t do your .NET development in C# with Visual Studio?

I’d gladly do it in c# in visual studio, I was just going to try and use dotNet since it seemed like an easier route to go rather than c#.

I’ve never used either one so I found dotNet easier to build since I could do it all in max as well.
Either one will be a fun challenge and something new for me.

I wonder if it would be more fun to quickly build my ui in maxscript then show everyone what I’m after and then convert that to dotNet or c#

So the next step now is developing a function that when the script is executed, it collects the needed information and creates a button for each file in the dialog window.

I wanted to say thanks to everyone Tim, Lo, and Pjanssen for checking out the post and responding with some helping words. I’m going to post more of my code for you guys to check out.

Stage 2
The different groups of buttons. Figuring out how it hide and unhides the buttons.

Do i have to make each buttons action within a function? Or can I do what is done when using maxscript and just do a direction action for example


on button pressed do (print "me")

instead of what I’m doing right now in dotNet which would be the equivalent of this in maxscript


function = (print "me")
on button pressed do function

Here is the updated code so far…


--Create a form and display it in Max. 
--Read about this process in the form & MaxForm tutorial. 
form=dotNetObject "form"


function ShowGroup1 = 
(
	btnMS1.visible = true
	btnMS2.visible = false
	btnMS3.visible = false
)

function ShowGroup2 = 
(
	btnMS1.visible = false
	btnMS2.visible = true
	btnMS3.visible = false
)

function ShowGroup3 = 
(
	btnMS1.visible = false
	btnMS2.visible = false
	btnMS3.visible = true
)

sysPointer=dotNetObject "system.intPtr" (windows.getMaxHWND())
maxHandle=dotNetObject "maxCustomControls.win32HandleWrapper" sysPointer
form.show maxHandle
form.bounds=dotNetObject "system.drawing.rectangle" 10 90 400 400
form.text="DotNet UI" 
	

btn1 = dotNetObject "system.windows.forms.button" 
btn1.bounds=dotNetObject "System.drawing.rectangle" 10 10 36 36
btn1.flatStyle=btn1.flatStyle.flat
btn1.backColor=btn1.backColor.darkRed
btn1.text="1"
	
btn2 = dotNetObject "system.windows.forms.button" height:50
btn2.bounds=dotNetObject "System.drawing.rectangle" 48 10 36 36
btn2.flatStyle=btn2.flatStyle.flat
btn2.backColor=btn2.backColor.darkGreen
btn2.text="2"
	
btn3 = dotNetObject "system.windows.forms.button"
btn3.bounds=dotNetObject "System.drawing.rectangle" 86 10 36 36
btn3.flatStyle=btn3.flatStyle.flat
btn3.backColor=btn3.backColor.darkBlue
btn3.text="3"

btnMS1 = dotNetObject "system.windows.forms.button" 
btnMS1.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24
btnMS1.flatStyle=btn1.flatStyle.flat
btnMS1.backColor=btn1.backColor.darkRed
btnMS1.text="MaxScript1.ms"
btnMS1.visible = false

btnMS2 = dotNetObject "system.windows.forms.button" 
btnMS2.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24
btnMS2.flatStyle=btn1.flatStyle.flat
btnMS2.backColor=btn1.backColor.darkGreen
btnMS2.text="MaxScript2.ms"
btnMS2.visible = false

btnMS3 = dotNetObject "system.windows.forms.button" 
btnMS3.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24
btnMS3.flatStyle=btn1.flatStyle.flat
btnMS3.backColor=btn1.backColor.darkBlue
btnMS3.text="MaxScript3.ms"
btnMS3.visible = false
	
--Add the pictureBox to the form
form.controls.add btn1
	form.controls.add btnMS1
form.controls.add btn2
	form.controls.add btnMS2
form.controls.add btn3
	form.controls.add btnMS3

--//Button actions
dotNet.addEventHandler btn1 "click" ShowGroup1
dotNet.addEventHandler btn2 "click" ShowGroup2
dotNet.addEventHandler btn3 "click" ShowGroup3

Aside from the above post…
How would I make the button even handler a function with a variable for example

I understand the basic fundamentals of coding in general. It’s just a matter of translating it over to dotNet. Once I begin to understand those it will be smooth sailing for sure.

Once again I appreciate all the help from you guys in the community. Thanks a ton for your patience and help.


--//Universal Function
function ShowGroup grp = 
(
	if grp == 1 do (
		btnMS1.visible = true
		btnMS2.visible = false
		btnMS3.visible = false
	)
	if grp == 2 do (
		btnMS1.visible = false
		btnMS2.visible = true
		btnMS3.visible = false
	)
	if grp == 3 do (
		btnMS1.visible = false
		btnMS2.visible = false
		btnMS3.visible = true
	)
)

--//Button actions
dotNet.addEventHandler btn1 "click" (ShowGroup 1)
dotNet.addEventHandler btn2 "click" (ShowGroup 2)
dotNet.addEventHandler btn3 "click" (ShowGroup 3)

Page 1 / 18