Adding DoubleClick Event to Flowlayoutpanel Buttons

i'm Trying to Add Doubleclick Event to flowlayoutpanel buttons but its not Working!, How Can i Fix That?
i Tried Both Ways (DoubleClick) and (MouseDoubleClick)
THANKS in ADVANCED

if test_roll != undefined then try(destroyDialog test_roll)catch()
rollout test_roll "TEST"
	(
		dotNetControl 'flp_test' "flowlayoutpanel" pos:[10,10] width:170 height:90
 
		fn add_btns =
		(
			for i = 1 to 6 do (
				btn = dotnetobject "Button"
	                     	btn.flatstyle = (dotNetclass "System.Windows.Forms.FlatStyle").flat
				btn.backcolor = (dotnetclass "System.Drawing.Color").FromArgb 40 40 40
	                	btn.forecolor = (dotnetclass "system.drawing.color").FromArgb 230 230 230
	                	btn.FlatAppearance.BorderSize = 0
				btn.text = i as string
				btn.tag = dotNetObject "System.String" "Its Working !"
 
	             		fn btn_DoubleClick = (print "Its Working !")
 
	         		fn btn_MouseDoubleClick btn arg = (
		        		if arg.button == arg.button.left do (print btn.tag)
	                	)
		           	dotNet.addEventHandler btn "MouseDoubleClick" btn_MouseDoubleClick
		         	dotNet.addEventHandler btn "DoubleClick" btn_DoubleClick
	        		dotNet.setLifeTimeControl btn #dotNet
		        	test_roll.flp_test.Controls.Add(btn)
			)
		)
		on test_roll open do (
			flp_test.backcolor = (dotnetclass "System.Drawing.Color").FromArgb 55 55 55
			flp_test.controls.clear()
			add_btns()
		)
	)
createdialog test_roll 190 110

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
obaida's picture

:)

Thank you very much jahman , best regards.

jahman's picture

.

As you exit add_btns function both btn_DoubleClick and btn_MouseDoubleClick cease to exist because of garbage collector.
Check dotNet.setLifetimeControl in reference

.upd my bad.. I see that you actually use it already

here's a workaround

if test_roll != undefined then try(destroyDialog test_roll)catch()
rollout test_roll "TEST"
	(
		dotNetControl 'flp_test' "flowlayoutpanel" pos:[10,10] width:170 height:90
 
		local prev_timestamp = timestamp()
 
		fn btn_MouseDoubleClick arg ev =
		(
			local t = timeStamp()
 
			if (t - prev_timestamp) < 200 do 
			(
				prev_timestamp = t
 
				format "Double clicked\n" 
			)
 
			prev_timestamp = t
		)
 
		fn add_btns =
		(
			for i = 1 to 6 do
			(				
				btn = dotnetobject "Button"				
				dotNet.addEventHandler btn "MouseUp" btn_MouseDoubleClick				
				dotNet.setLifeTimeControl btn #dotNet
				test_roll.flp_test.Controls.Add btn
			)
		)
		on test_roll open do
		(
			add_btns()
		)
	)
createdialog test_roll 190 110

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.