02-22-2012 03:35 AM
I have implemented a 3 position toggle switch using an XControl.
The positions are:
Up (Return to centre)
Centre
Down
Static positions for the switch are the down and centre. When the toggle switch is moved from the centre position to the up position, it will remain there as long as the left mouse button is held down. On release it snaps back to the centre position.
The toggle control uses a slide control for switching and a ring indicator to display the switch positions.
The control works as required with one exception.
If the switch is moved to the up position and the left mouse button is released it snaps back to the centre which is correct.
If however, the switch is moved to the up position and the mouse moved outside of the control, when the left mouse button is released the switch remains in the up position which is incorrect.
I use the ‘Mouse up’ event to detect the button release.
I think the reason this happens is because when the mouse is moved outside the XControl it looses focus and the ‘Mouse up’ event is not detected.
If this is the case then why when I select the up position, keep the left mouse button down, and move outside the XControl, can I still move the switch position to any position i.e. down centre or up. In this case the focus seems to still be on the XControl.
Is there something I am missing?
02-22-2012 03:47 AM
02-22-2012 05:53 AM
Hi Mike
Thanks for the post regarding my XControl issue.
I am not sure I understand why I need to track the mouse position.
I need the switch to snap back to the centre position when the left mouse is released regardless of the position of the mouse.
Just to clarify the operation.
I did try using the slider ‘Mouse Leave’ event. When the mouse moved outside the XControl it did snap back to the centre, but then the switch reverted to the up position maybe because the mouse down was still active. This was not really going to be a solution as it should only snap back when the mouse button is released.
The reason this is an issue is that an operator can drag the switch from the down position to the up position, continue moving the mouse up i.e. outside the XControl, whilst holding the mouse down. Then when the operator releases the mouse button the expected snap back does not happen.
I would appreciate your thoughts,
Thanks
John Lee
02-22-2012 08:21 AM
The idea is to use the mouse position to determine when you are no longer over the control. At that point you would execute the same logic as when you mouse up.
Mike...
02-23-2012 06:50 AM
Mike
I now understand your suggestion to use the mouse positioning to implement the same logic as the mouse up when the mouse is no longer over the control.
I did implement this before using the slide control ‘Mouse Leave’ event. The switch did snap back to the centre position as the mouse drifted outside of the control.
There are two issues with this solution:
It appears to me that for the slide control within the XControl:
I am not sure there is a solution to this. I will need to ponder on it.
Thanks again for the feedback,
John Lee