Hi all and happy new year
I need to detect whe the mouse leftclick is being held while moving the mouse upward so how can i do that

Thank you

Recommended Answers

You need to capture the MouseDown and MouseUp event, set a boolean, and remember the original coordinates:

bool MouseIsDragging = false;
point Start = new point();
private void MyForm_MouseDown(object sender, MouseEventArgs e)
{
    MouseIsDragging = true;
    Start.X = e.X;
    Start.Y = e.Y;
}
private void MyForm_MouseUp(object sender, …
Jump to Post

All 2 Replies

You need to capture the MouseDown and MouseUp event, set a boolean, and remember the original coordinates:

bool MouseIsDragging = false;
point Start = new point();
private void MyForm_MouseDown(object sender, MouseEventArgs e)
{
    MouseIsDragging = true;
    Start.X = e.X;
    Start.Y = e.Y;
}
private void MyForm_MouseUp(object sender, MouseEventArgs e)
{
    MouseIsDragging = false;
    if (e.Y > Start.Y) //can't remember if Y increases or decreases as you go up...
        MouseHasBeenDraggedUp(); //Condition is met, do something
}

//If this needs to be monitored in realtime, and not just when the mouse button is up:
private void MyForm_MouseHover(object sender, MouseEventArgs e)
{
   if (MouseIsDragging == true && e.Y > Start.Y)
   {
      MouseHasBeenDraggedUp();// Condition met
   }  
}

thank you it helped me alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.