If you really have to use an image, then there are a few things you can do to test the "click".
Check the time between two events. If it is less than your threshold, then treat with the mouse as a click. You will need to save the time of the mouse event.
Verify that the sender value of both events is the same. Again you will need to save the sender mouse event.
You can also verify that the left button has been pressed and released.
Combination of two:
private DateTime downTime; private object downSender; private void Image_MouseDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { this.downSender = sender; this.downTime = DateTime.Now; } } private void Image_MouseUp(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Released && sender == this.downSender) { TimeSpan timeSinceDown = DateTime.Now - this.downTime; if (timeSinceDown.TotalMilliseconds < 500) {
In fact, you can do the third thing: check the position of the mouse.
private Point downPosition;
save position:
this.downPosition = e.GetPosition(sender as Image);
then check it in the MouseUp event, again with a valid value.
source share