tags:

views:

300

answers:

2

How do I detect if the left mouse button is being held down in the OnMouseMove event for a control?

A: 

Simply have a boolean set to true when the left mouse button is held and set it to false when its released.

If you check the condition of the bool when you fire the OnMouseMove event then you will be able to find out if its held down or not.

Psuedo code:

private bool isDown;

MouseDown()
{
   isDown = true;
}

MouseUp()
{
   isDown = false;
}
OnMouseMove()
{
   if(isDown)
   {
       //Do something...
   }
}
Jamie Keeling
A: 

Your eventhandler for the OnMouseMove event should recieve a MouseEventArgs that should tell you if the left button is pressed

private void mouseMoveEventHandler(object sender, MouseEventArgs e)
{
   if(e.Button == MouseButtons.Left)
   {
     //do left stuff
   }
   else 
   {
     // do other stuff
   }
}
Nifle