[Closed] on click btn inside dotnetcontrol panel
I have btns which are created inside a dotnet panel. Each time these btns can be different.
try(destroyDialog testR)catch()
rollout testR "Test" width:400 height:400
(
dotnetcontrol pn "Panel" pos:[5,5] width:390 height:378
fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)
local COL1 = (defColor 80 80 80), COL2 = (defColor 150 150 150)--, COL3 = (defColor 65 125 88), COL4 = (defColor 125 150 80)
local ctrlsIn2st=#()
fn defBtn txt: w: h: cnt:0 =
(
print h
btn = dotnetobject "Button"
btn.text = txt
btn.backcolor = COL2
btn.width = w ; btn.height = h
btn.Location = dotNetObject "System.Drawing.Point" 5 (-15 + (cnt*btn.height))
btn
)
on testR open do
(
pn.backcolor = COL1--pn.backcolor.blue
pn.BorderStyle = pn.BorderStyle.FixedSingle
pn.width = 390 ; pn.height = 390
for i=1 to 5 do -- add mat id buttons
(
append ctrlsIn2st (defBtn txt:(i as string) w:20 h:60 cnt:i)
)
pn.controls.addRange ctrlsIn2st
)
)
createDialog testR
Except this, I have an array with btns – btnarray
I need somehow to have access to these btns:
if btnarray.count!=0 then
for i=1 to btnarray.count do
on (testR.pn.controls.Item[i]) click do
(
print btnarray[i]
)
I know I have errors here, and that this is not right logic at all, but I wanted to explain somehow what I need.
when you create a button just simply add event handler for every one (dotnet.addEventHandler)
Oh, yess! I did it before but I forgot. How could I!?.. Thank you, Denis!
Oops, I have just found a limitation:
dotNet.addEventHandler btn "MouseDown" my_fn my_arument
I cannot use arguments for my_fn
How to get btnarray[i] if I cannot call the function my_fn with argument i?
because I need these btns to be function-able. I need for every certain btn to check the scene objects and so on.
This is the script I made some time before. Just btns from the left have to become function-able. Every btn has it’s material inside btnarray.
when adding
for i = 1 to …
dotNet.addEventHandler btn “MouseDown” select_by_mat_fn btnarray[i]
I need for every btn i to have assigned the material from btnarray[i]
most of .net form controls have “Tag” property. Pass whatever you want with it. There many samples of using this property on this forum
I know Denis, about tag, but I cant understand how to use it in other function:
fn select_by_mat_fn =
(
print thisbtn.tag -- where should I get thisbtn from?
)
for i = 1 to ..
(
...
btn.tag = btnarray[i]
dotNet.addEventHandler btn "MouseDown" select_by_mat_fn
)
fn select_by_mat_fn [B]sender args[/B] =
(
print sender.tag
)
for i = 1 to ..
(
...
btn.tag = btnarray[i]
dotNet.addEventHandler btn "MouseDown" select_by_mat_fn
)