krrishna
krrishna

Reputation: 2078

How to know if the mouse or touch is released when control is on a particular ui element

I have a block of images(these images are embedded in border controls) and they are arranged in 4 rows and 4 columns. When user swipes from one image to another image from left to right or right to left or diagonal, I want to know what are all those images traversed ?

I found MouseEnter and MouseLeave events .But if user touches the image1 (in row1) and drags the swipe to image4 leaves the mouse how do I know if the user is done with the swipe ? Because user might touch anywhere on the screen after leaving the mouse at image4.

What is the best way to capture the those traversed images ? list or a dictionary?

Upvotes: 2

Views: 482

Answers (1)

Zeddy
Zeddy

Reputation: 2089

As per this article...... http://msdn.microsoft.com/en-us/library/system.windows.uielement.mouseleftbuttondown(v=vs.95).aspx

You can detect WHICH tile/square the MOUSE SWIPE STARTED IN by using the MouseLeftButtonDown event

And then if the user SWIPES his mouse across different objects as the article says....

The LeftMouseButtonUp event will execute though the LeftMouseButtonDown WONT execute for that same tile as the ACTUAL down event happend in another square/tile/image!!

So if you have a simple 4x4 matrix/array to hold the SWIPE YES/MO values... Like 1 or yes the mouse swiped THROUGH this element and 0 NO the mouse NEVER enetered this tile/image/element... then you should be fine...

And using the age old rule of ....

If X1 > X2 then mouse movement was Right to left (moving left)

If X2 > X1 then mouse movement was left to right (moving right)

If Y1 > Y2 then mouse movement was down to up (moving up)

If Y2 > Y1 then mouse movement was up to down (moving down)

And mix and match those rules for diagonal movement/swipes....

Where X1,Y1 is the MouseDown screen values and X2,Y2 is the MouseUp screen values

Edit

According to the text in the REMARKS section...

Quote

The MouseLeftButtonDown event is raised when the left mouse button is pressed (or when the tip of the stylus touches the tablet PC) while the mouse pointer is over the UIElement. When the mouse button (or the tip of the stylus) is released, the MouseLeftButtonUp event is raised. However, if the mouse pointer (or the stylus) is moved over another object when the button is released, the UIElement that received the MouseLeftButtonDown event will only receive the MouseLeftButtonUp event if that UI element has explicitly captured the mouse. There is no discrete double-click event. A double-click consists of two sequences of MouseLeftButtonDown and MouseLeftButtonUp events. Click count can be captured using event data (ClickCount).

Use a handler based on MouseButtonEventHandler to handle this event. For more information on how to handle mouse events, see Mouse Support.

Mouse capture is a concept whereby an object can continue to receive mouse events, even if the mouse pointer (or the stylus) is no longer over the object's bounding area. In order to request mouse capture, the mouse left button (or the stylus) must be in a pressed (down) state. Therefore, a common point in code to call CaptureMouse is from within the MouseLeftButtonDown handler for a particular UIElement. For more information on mouse capture and scenarios where it is useful, see Mouse Support or How to: Drag and Drop Objects in UI Layout.

End of Quote

So contrary to my first solution sorry, i must have misread the remarks, although the third paragraph which begins MOUSE CAPTURE IS A CONCEPT.... Clarifies that you should still be able CAPTURE the Mouse up event even though it is OUTSIDE the INITIAL CONTROL that invoked the mouseevent meaning the MOUSEDOWN event and that would be from the ORIGINAL control, so saying you begin your swipe from control1, and the Control1 MouseLeftButtonDown event fires then you need to CAPTURE the mouse (For more information on mouse capture and scenarios where it is useful, see Mouse Support or How to: Drag and Drop Objects in UI Layout) then as you stated you swipe across control2 and when your finger/pointer/stylus isover control3 you RELEASE the mouse then the ORIGINAL CAPTURED mouseup event will fire for the CONTROL which CAPTURED the mouse (in this case control1) and using the screen X/Y location and your controls X/Y/Width/HEIGHT properties you should be able to assess OVER which control the mouse was released.

If I had more time I would have read it more carfeully and saved myself from giving you nearly correct information rather than correct information, I recommend you read carefully the article in depth and also follow the mouse capture process and try that and dont forget that when you release the mouse even though itmay be over ANOTHER control the ACTUAL mouseup event will be fired for the CONTROL that CAPTURED the mouse.

Sorry for my earlier mistake too - thats what happens when you skip read.

Upvotes: 1

Related Questions