[Closed] DotNet ButtonUp ?
MouseUp event
-
when I press the button and leave, then a action is executed, thats right…
2) when I press the button and move mouse cursor out of form, then a action executed
thats not good…Is there any way to avoid this ?
fn onBtnMouseUp s a =(if a.Button == a.Button.left do format "button up:%
" s.text)
fn initButtons t =
(
t.controls.addrange \
(
for i = 1 to 4 collect
(
local b = dotNetObject "Button"
b.text = i as string
b.FlatAppearance.BorderSize = 1
b.margin = dotnetobject "padding" 0
dotNet.addEventHandler b "MouseUp" onBtnMouseUp
b
)
)
)
f=dotnetobject "form"
t=dotNetObject "TableLayoutPanel"
initButtons t
f.controls.add(t)
f.show()
How about in the leave handler for the form you set a flag that is checked in the mouse up handler for the button. If true do it if false don’t.
Why not use the Button’s MouseClick event instead? This one already does the work for you as it only fires when the mouse is pressed and released inside the button’s client area.
Martijn
as an alternative to Paul’s idea, you could check to see if the bounds of the form contains the mouse up XY location like so:
fn onBtnMouseUp s a =
(
p = s.PointToScreen (dotnetobject "System.Drawing.Point" a.x a.y)
if a.Button == a.Button.left AND s.TopLevelControl.Bounds.Contains p do format "button up:%
" s.text
)
Good point Martijn! MouseClick works fine
this word MouseUp is little bit confusing heh…
Many Thanks Guys.