Notifications
Clear all
[Closed] Accessing functions/variables of "System.Windows.Forms.Form" from outside?
Apr 29, 2019 5:30 am
Is it possible when I press the “Click Me” button in hForm1 the findRootObjs() function that “belongs” to hForm to be executed and the result to be printed in the listener?
Here is the code:
(
try(hForm1.close())catch()
global hForm1 = dotNetObject "System.Windows.Forms.Form"
hForm1.size = dotNetObject "System.Drawing.Size" 500 300
btn_clickMe = dotNetObject "System.Windows.Forms.Button"
btn_clickMe.Location = dotNetObject "System.Drawing.Point" 10 10
btn_clickMe.Text = "Click me"
hForm1.controls.add btn_clickMe
fn btn_clickMe_Click =
(
hForm.findRootObjs()
)
dotNet.AddEventHandler btn_clickMe "Click" btn_clickMe_Click
ok
)
(
clearListener()
local rootObjs=#()
local tvObjs = dotNetObject "System.windows.forms.treeview"
tvObjs.text= "Objects On Scene"
tvObjs.size= dotNetObject "System.Drawing.Size" 200 200
tvObjs.location=dotNetObject "System.Drawing.Point" 20 30
btn_openNewForm = dotNetObject "System.Windows.Forms.Button"
btn_openNewForm.Location = dotNetObject "System.Drawing.Point" 250 200
btn_openNewForm.Text = "Open form"
local chkObjs = dotNetObject "System.windows.forms.checkbox"
try(hForm.close())catch()
global hForm = dotNetObject "System.Windows.Forms.Form"
hForm.size = dotNetObject "System.Drawing.Size" 500 300
-- hForm.TopMost=true
hForm.controls.add tvObjs
hForm.controls.add btn_openNewForm
fn findRootObjs=
(
rootObjs=#()
for o in objects do
(
if o.parent==undefined then append rootObjs o
)
format "rootObjs: % \n" rootObjs
)
fn recurseHierarchy obj treeNode=
(
for i = 1 to obj.children.count do
(
recurseNode= (dotNetObject "System.Windows.Forms.TreeNode" obj.children[i].name)
treeNode.nodes.add recurseNode
recurseHierarchy obj.children[i] recurseNode
)
)
fn populateTreeView=
(
findRootObjs()
for x in rootObjs do
(
newNode=(dotNetObject "System.Windows.Forms.TreeNode" x.name)
tvObjs.nodes.add newNode
recurseHierarchy x newNode
)
)
fn nodesSelected=
(
print tvObjs.selectedNode.text
if (getNodeByName tvObjs.selectedNode.text).IsSelected then
(
deselect (getNodeByName tvObjs.selectedNode.text)
)
Else
(
selectmore (getNodeByName tvObjs.selectedNode.text)
--sel=for o in selection collect o
)
if zoomChk==true then
(
max zoomext sel
)
)
fn nodesChkd args=
(
print args.node.text
tvObjs.selectedNode=args.node
)
fn btn_openNewForm_Click =
(
findRootObjs()
hForm1.show()
)
dotNet.AddEventHandler btn_openNewForm "Click" btn_openNewForm_Click
fn formLoad=
(
clearListener()
populateTreeView()
tvObjs
tvObjs.checkboxes=true
)
dotNet.addEventHandler hForm "Load" formLoad
dotNet.addEventHandler tvObjs "AfterSelect" nodesSelected
dotNet.addEventHandler tvObjs "AfterCheck" nodesChkd
hForm.show()
ok
)
2 Replies
Apr 29, 2019 5:30 am
Let’s clarify your question …
Do you want to click a button in the .net window (form)?
- the answer is YES. You can
try(form.close())catch()
global form =
(
--form = dotNetObject "System.Windows.Forms.Form"
form = dotnetobject "MaxCustomControls.Maxform"
form.size = dotNetObject "System.Drawing.Size" 500 300
btn_clickMe = dotNetObject "System.Windows.Forms.Button"
btn_clickMe.Location = dotNetObject "System.Drawing.Point" 10 10
btn_clickMe.Text = "Click me"
form.controls.add btn_clickMe
fn btn_clickMe_Click =
(
format ">> %\n" (objects as array)
)
dotNet.AddEventHandler btn_clickMe "Click" btn_clickMe_Click
form.show()
form
)
/*
form.controls.item[0].PerformClick()
*/
Do you want to define a function and add it to the .net window (form)?
- the answer is NOT easy. You have to write you own class derived of Form and add your own methods to it.
Apr 29, 2019 5:30 am
Thank you.
So, the functions and the variables have to be global(or members of a struct).