Notifications
Clear all

[Closed] maxform.backcolor ?

Hi,
I am using a dotnet MaxForm control and i can’t set the backcolor as i would with aclassic dotnet Form :

(
     	Form = dotNetObject "System.Windows.Forms.Form"	
     	maxForm = dotNetObject "MaxCustomControls.MaxForm"
     	
     	Form.backcolor=maxform.backcolor=(dotnetclass "System.Drawing.Color").FromARGB 255 0 0
     	
     	Form.show()
     	maxForm.showmodeless()
     )
     
 I want to use MaxForm because i have some problems with the classic dotnet form integration in max. (i can't get focus on textbox etc... whereas maxform works for that)
 
 when i :
showproperties (dotNetObject "MaxCustomControls.MaxForm")
 it returns the backcolor property, but setting any color will not work

i also went into the 3dsMaxDotNetSDKRef.chm help reference. (in 3dsmax SDK / Help)
Namespaces > MaxCustomControls > MaxForm
There i can see :
BackColor (Inherited from Form.)

There is also a method UpdateColors :
Updates the form’s colors according to the current CUI settings.

So a MaxForm backcolor depends on the colors of the Customize User Interface ?
Is there a solution to override this ?

Thanks

4 Replies

you just override the backcolorchanged event


maxForm = dotNetObject "MaxCustomControls.MaxForm"
Form.backcolor=(dotnetclass "System.Drawing.Color").FromARGB 255 0 0
fn changeBackcolor = (maxForm.backColor = (dotnetclass "System.Drawing.Color").FromARGB 255 0 0)
dotnet.AddEventHandler maxForm "BackColorChanged" changeBackcolor
maxForm.showmodeless() 

Edit :

another solution would be to change the Property after you create the form ,
but this will not be very suitable for different UI schemes


maxForm = dotNetObject "MaxCustomControls.MaxForm"
Form.backcolor=(dotnetclass "System.Drawing.Color").FromARGB 0 0 255
maxForm.showmodeless()
maxForm.backColor = (dotnetclass "System.Drawing.Color").FromARGB 255 0 0

I dont know , if I understand what you need, maybe this ?

(
    local bgColor   = ((colorMan.getColor #background)*255)as color
    local textColor = ((colorMan.getColor #text)*255)as color
    fn netDrColor clr = ((dotNetClass "Drawing.Color").fromArgb clr.r clr.g clr.b)
    form = dotnetobject "form"
    lbl = dotnetobject "label"
    lbl.backcolor =  netDrColor bgColor
    lbl.forecolor =  netDrColor textColor
    lbl.text = "max text color"
    form.controls.add lbl
    form.backcolor =  netDrColor bgColor
    form.show()
)

@ Cyfer : The solution where you override the backcolorchanged event is working fine for me . Coool
But changing the Property after i create the maxform does not work in my case, maybe i have a bas UI Scheme ??

@Merlin : it seems that you use a standard dotnet form, i had a problem with the maxform

Thanks for the help!

It’s because the maxform’s backcolor is automatically bound to the background of your max UI, meaning you dont need to pass it a color each time you open it. If you want to have an alternate color, you could do a few things, like the override method. You could also, in the case of using a textbox, enable and disable the accelerators on the textbox lostfocus and gotfocus events to minick this functionality and use a starndard windows form.

I do a similar thing in my custom UI controls but call a MXS function via the managedservices dll in the ‘new’ constructor to get the UI color from Max and set the backcolor on creation, avoiding the flash as it draws the background and then re-draws the correct color.