How do I detect if the left mouse button is being held down in the OnMouseMove
event for a control?
We can listen to the mousedown and mouseup events to check if a mouse button is kept down after we press the mouse button. We set the window. onmousedown and window. onmouseup properties to functions that change the mouseDown count to listen for the mousedown and mouseup events on the whole tab.
Drag and drop is when you move something from one place to another. First select the item with the left mouse button and keep the button pressed down. Then move the mouse and the item on screen will move with the cursor. When you have the cursor and item in the position you want, release the left mouse button.
MouseDown occurs when the user presses the mouse button; MouseUp occurs when the user releases the mouse button.
You can detect which button has been clicked by checking the MouseEvent. button property. This property will be available on mouse clicking events like: mousedown , mouseup , click , dblclick , contextmenu . The MouseEvent.
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With