Notifications
Clear all

[Closed] dotNetObject inside a function, how to?

hi

my goal is getting something like dynamic UI and add buttons labels as needed.

when calling dotnet objects inside functions it works , problem is Events see the dotnetobject as undefined.

here is the code




form=dotNetObject "form"

form.show()

--what does work

test1=dotNetObject "button"
test1.text = "test1"
test1.bounds = dotNetObject "system.drawing.rectangle" 30 50 40 30 
form.controls.add test1




--what doesnt work
--local test2
fn add_dn_but nme txt =
	
(
	nme=dotNetObject "button"
	nme.text = txt
	form.controls.add nme
)

add_dn_but test2 "test2"





		mouseIsDown=false
		mouseRIsDown=false
		mouseMIsDown=false

fn formMouseDown sender arg=
(
	if arg.button==arg.button.left do
	(
		mouseIsDown=true
		mouseRIsDown=false
		mouseMIsDown=false
		print "left"
	)
	if arg.button==arg.button.right do 
	(
		mouseRIsDown = true
		mouseIsDown=false
		mouseMIsDown=false
		print "right"
	)
		if arg.button==arg.button.middle do 
	(
		mouseMIsDown= true
		mouseIsDown=false
		mouseRIsDown=false
		Print "middle"
	)
	
	
	
)
fn formMouseUp sender arg=
(
	mouseIsDown=false
	mouseRIsDown=false
	mouseMIsDown=false
)

dotNet.addEventHandler test1 "mouseDown" formMouseDown
dotNet.addEventHandler test1 "mouseUp" formMouseUp

-- xxxxxxxxxxxxxxxxxxxxxx
dotNet.addEventHandler test2 "mouseDown" formMouseDown
dotNet.addEventHandler test2 "mouseUp" formMouseUp


for sure i’m missing something or it can’t be done this way

3 Replies

This post by lo a while ago should answer any questions you have about building dotNet controls in functions. It’s a really neat idea to reduce repetitive code.

http://forums.cgsociety.org/showpost.php?p=7151882&postcount=15

Taken from this thread which is definitely worth a read: http://forums.cgsociety.org/showthread.php?t=1015046

struct way in “lo” post seem complicated but i’ll try to pick it up

any other normal scripting way will be great
i’ll read the other link

thanks in advance

finally fixed

for anyone wants to know how


  fn add_dn_but txt = --anyotheroptions
  	
  (
  	local nme=dotNetObject "button"
  	nme.text = txt
  	nme.bounds = dotNetObject "system.drawing.rectangle" 0 20 40 30 
  	nme
  )
  
  test2 = add_dn_but "test2"
  

just that simple
i didn’t try it inside “for loop” but i geuss it will work fine