Search code examples
c#winformsonmousemove

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


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


Solution

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