954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

detect when mouse is bieng hold and moved upward

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

shandoosheri
Light Poster
42 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

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
   }  
}
skatamatic
Posting Shark
959 posts since Nov 2007
Reputation Points: 403
Solved Threads: 129
 

thank you it helped me alot

shandoosheri
Light Poster
42 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: