See if left mouse button is held down in the OnMouseMove event

SchwartzE picture SchwartzE · Feb 2, 2010 · Viewed 16.3k times · Source

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

Answer

Nifle picture Nifle · Feb 2, 2010

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
   }
}