dotNetObject inside a function, how to?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  11 November 2012
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
__________________
 
  11 November 2012
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/showpos...82&postcount=15

Taken from this thread which is definitely worth a read: http://forums.cgsociety.org/showthread.php?t=1015046
 
  11 November 2012
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
__________________
 
  11 November 2012
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
__________________

Last edited by doctor3dmax : 11 November 2012 at 01:28 AM.
 
  11 November 2012
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:11 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.