Using Inheritance to build a custom control

One of the really good things about writing your own controls in Visual Studio is the ability to not actually write one. This is great because you don't have to do any of the hard work, you just pick the control that is closest to the functionality you want, then inherit the class. This is much the same if as using extends in a scripted plugin. What this does is gives you a fully featured version of the control and allows you to build extra properties and methods for the bits you want to add, or override the existing properties to do something flash.

In this case, i'm not doing this at all, but I am just tailoring the button control to be integrated into 3dsMax in a more direct way. If you use a dotnetcontrol constructor to implement a dotnet button onto a MXS form, you will get a default instance of a windows.forms.button, which you then have to alter in the rollout's load event. This isn't problem really, but i wanted to see if it was possible to build a class that returned a button in the correct visual state from the word go, leaving very few, if any, things to do in the load event. The first property I wanted to implement was to return a flat button with a background color the same as 3dsMax's default UI color. The other things I experimented with was the idea of using embedded resources to hold common UI icons, rather like the examples on the GDI+ article i wrote a while ago. I also wanted a one line method to align the text and image around in a logical way.

It doesn't avoid the issue of having to perform some UI stuff in the rollout open handler, but it does most of what you need for you. You also avoid the flicker of the controls as they redraw themselves with the correct background color. If you still want to build MXS rollout rather than dedicated Dotnet rollouts this could be a reasonable solution. (Don't forget, if you build a dotnet form with the MaxForm class in 3dsMax, the controls will take on the correct UI color automatically.)

Using DotNet Enums in MaxScript

With any custom class objects, it's highly likely Enums will be used, as they are a way of organizing custom properties into easily recognizable names, rather like structs in MXS have members to describe elements so that you don't have to resort to array elements with confusing index numbers.

To use an enum in 3DSMax, you use a plus symbol in between the class string and the enum type. therefore, in the maxbutton class, to get the enums used you would type the following -

(dotnetclass "LoneRobot.Controls.MaxButton+CustomIcons").NewDocument

(dotnetclass "LoneRobot.Controls.MaxButton+LayoutStyles").Top

(dotnetclass "LoneRobot.Controls.MaxButton+ColorPresets").MaxUIDark

you would then use this to set the custom properties in the class.

Here is the full class diagram of the Maxbutton Control -

I hope this article has been of interest to you. Please download the class library and try it for yourself. there is a basic MXS script that builds the rollout at the top of the page. You can explore trying the different enums for yourself!