Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse click and drag Event WPF

I am developing an analog clock picker control. The user is able to click on the minute or hour hand and drag to turn the needle to select the specific time. I was wondering how to detect such a click and drag event.

I tried using MouseLeftButtonDown + MouseMove but I cannot get it to work as MouseMove is always trigger when the mousemove happen despite me using a flag. Is there any easier way?

public bool dragAction = false;

private void minuteHand_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    dragAction = true;
    minuteHand_MouseMove(this.minuteHand, e);
}

private void minuteHand_MouseMove(object sender, MouseEventArgs e)
{
    if (dragAction == true)
    {
       //my code: moving the needle
    }
 }

 private void minuteHand_MouseLeftButtonUp(object sender, MouseEventArgs e)
 {
    dragAction = false;
 }
like image 935
Ji yong Avatar asked Jul 03 '13 07:07

Ji yong


1 Answers

I think this is the easiest and most straightforward way :

 private void Window_MouseMove(object sender, MouseEventArgs e) {
     if (e.LeftButton == MouseButtonState.Pressed) {
        this.DragMove();
     }
 }
like image 163
George TG Avatar answered Oct 21 '22 22:10

George TG