PDA

View Full Version : DotNet ButtonUp ?


MerlinEl
01-21-2010, 07:13 AM
MouseUp event

1) 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:%\n" 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()

PEN
01-21-2010, 11:55 AM
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.

magicm
01-21-2010, 01:58 PM
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

Gravey
01-21-2010, 02:08 PM
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:%\n" s.text
)

MerlinEl
01-21-2010, 02:21 PM
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


Good point Martijn! MouseClick works fine :thumbsup:
this word MouseUp is little bit confusing heh...

Many Thanks Guys.

CGTalk Moderation
01-21-2010, 02:22 PM
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.