[Closed] dotNet controls .enabled property
I’m having a hard time reading the correct .enabled property of a dotNet control in a max rollout.
example code:
rollout Enabledstuff "qwerty" height:60
(
dotNetControl testControl "System.Windows.Forms.TextBox" width:100
on Enabledstuff open do
(
testControl.enabled=false
format "control is enabled? %
" testControl.enabled
)
)
createDialog Enabledstuff
listener output:
control is enabled? true
I should point out that the control does infact get enabled/disabled when I set the property, it’s only the reading the property back that gives the wrong result.
Does anyone have any information on why this is?
edit: Silly workaround – whenever I set the .enabled property of the control, I also set the .tag property of the control to the same value, and then whenever I need to check, I check the .tag and not the .enabled :shrug:
i think its because dotnet’s System.Windows.Forms controls have an enabled property and standard maxscript controls including the ‘dotnetcontrol’ wrapper also have an enabled property. the dotnetcontrol wrapper is taking priority when you ‘get’ the enabled value but the actual dotnet control (textbox in this case) is being ‘set’ properly.
anyway, you can get the real value using a cool feature of dotnet called reflection. The ‘GetDotNetProperty’ function in the code below will get the value of any property of any dotnet object including dotnet controls.
Note that the propName argument is case sensitive so ‘Enabled’ works but ‘enabled’ throws an error.
try(destroyDialog Enabledstuff)catch()
rollout Enabledstuff "qwerty" height:60
(
dotNetControl testControl "System.Windows.Forms.TextBox" width:100
fn GetDotNetProperty o propName =
(
propertyInfo = ( o.GetType() ).GetProperty propName
propertyInfo.GetValue o undefined
)
on Enabledstuff open do
(
testControl.enabled=false
format "control is enabled? %
" testControl.enabled
format "control is enabled? %
" (GetDotNetProperty testControl "Enabled")
)
)
createDialog Enabledstuff