[Closed] Using .NET forms launched by scripted plugin
Hi,
Once again I’m having trouble with .NET controls losing event handlers.
I’ve got a scripted material. This material has got a button to launch a dialog. In this dialog the user can pick different textures. When doubleclicking a texture in the dialog, the texture is loaded back into the material and the form closes. At least, that’s the idea.
I’ve got my scripted material working fine, and the external dialog works fine too. It’s a .NET form with .NET controls. Since it uses listviews and drag&drop I can’t code it back to normal max controls.
The problem: I can launch the dialog from the scripted material but the controls on that dialog don’t react. I don’t know if there’s a problem with the event handlers or if it’s a scoping issue. The example should demonstrate the problem (made in max2008 64bit). Could someone help me?
plugin material fileInShader
name:"fileInShader"
classID:#(0x7b6be4e2, 0x761ff1e6)--has to be unique, use genClassID() to generate an ID
extends:standard
replaceUI:true
version:1
(
struct maxFormStruct
(
theForm,
theButton,
function fn_declare =
(
theForm = dotNetObject "MaxCustomControls.MaxForm"
theButton = dotNetObject "button"
),
--define and construct the form
function fn_init =
(
--button
theButton.Dock = theButton.Dock.fill
theButton.text = "Press me to print stuff"
--maxform
theForm.Size = dotNetObject "System.Drawing.Size" 400 200
theForm.Text = ".NET form"
theForm.controls.add theButton
),
function event_printStuff = print "stuff",
declare = fn_declare(),
init = fn_init(),
handler = dotNet.addEventHandler theButton "mouseClick" event_printStuff,
show = theForm.ShowModeless()
)
rollout rollTest "Test if other dialogs with .NET controls work"
(
button btnLaunch "Launch dialog"
on btnLaunch pressed do maxFormStruct()--launch the .NET form
)
)
No, that doesn’t fix it either. These event handlers don’t need those arguments, but i’ve tried it anyway. No luck…
Klaas
Your problem really confused me a lot for a about a week …
And finally I find out what’s wrong:
struct maxFormStruct
(
theForm,
theButton,
function fn_declare =
(
theForm = dotNetObject "MaxCustomControls.MaxForm"
theButton = dotNetObject "button"
),
--define and construct the form
function fn_init =
(
--button
theButton.Dock = theButton.Dock.fill
theButton.text = "Press me to print stuff"
--maxform
theForm.Size = dotNetObject "System.Drawing.Size" 400 200
theForm.Text = ".NET form"
theForm.controls.add theButton
),
function event_printStuff val1 val2 = (print "stuff"),
declare = fn_declare(),
init = fn_init(),
handler = dotNet.addEventHandler theButton "mouseClick" event_printStuff,
show = theForm.ShowModeless()
)
f1 = maxFormStruct() ----------*see this tiny thing here*----------
plugin material fileInShader
name:"fileInShader"
classID:#(0x7b6be4e2, 0x761ff1e6)--has to be unique, use genClassID() to generate an ID
extends:standard
replaceUI:true
version:1
(
rollout rollTest "Test if other dialogs with .NET controls work"
(
button btnLaunch "Launch dialog"
on btnLaunch pressed do f1--launch the .NET form
)
)
I think you just have one structure defined but not created any instance of the structure so your code did not work well .
Hi HuaMuLan,
thanks for the suggestion but it isn’t exactly what I’m looking for.
I want to create the dialog from within the scripted material. This only works if the struct which contains the form also is located within the plugin code (afaik). The issue is not how to display the dialog, but how to get a .NET form working which has been launched from within a scripted material.
Klaas
I dont know if this will help, but if u create an instance of the struc when you press the button inside of the form, it will open and display the form
struct maxFormStruct
(
theForm,
theButton,
function fn_declare =
(
theForm = dotNetObject "MaxCustomControls.MaxForm"
theButton = dotNetObject "button"
),
--define and construct the form
function fn_init =
(
--button
theButton.Dock = theButton.Dock.fill
theButton.text = "Press me to print stuff"
--maxform
theForm.Size = dotNetObject "System.Drawing.Size" 400 200
theForm.Text = ".NET form"
theForm.controls.add theButton
),
function event_printStuff val1 val2 = (print "stuff"),
declare = fn_declare(),
init = fn_init(),
handler = dotNet.addEventHandler theButton "mouseClick" event_printStuff,
show = theForm.ShowModeless()
)
--f1 = maxFormStruct() ----------*see this tiny thing here*----------
plugin material fileInShader
name:"fileInShader"
classID:#(0x7b6be4e2, 0x761ff1e6)--has to be unique, use genClassID() to generate an ID
extends:standard
replaceUI:true
version:1
(
rollout rollTest "Test if other dialogs with .NET controls work"
(
button btnLaunch "Launch dialog"
on btnLaunch pressed do (
f1 = maxFormStruct()
)
)
)
or did you mean to create the .net form inside the rollout as part of the scripted materia rather than a pop out dialog box?
EDIT: sorry the code opens the box, but doesnt do the event handlers, how very strange…