I need to find a way to check if the mouse moves in c#, while the left button is down.
On Windows 10, head to Settings > Devices > Mouse. Under “Select your primary button,” ensure the option is set to “Left.” On Windows 7, head to Control Panel > Hardware and Sound > Mouse and ensure “Switch primary and secondary buttons” isn't checked. The ClickLock feature can also cause strange issues.
The button property returns a number that indicates which mouse button was pressed when a mouse event was triggered. This property is mostly used together with the onmousedown event. Note: This property is read-only.
The following example shows how to determine whether the left mouse button is pressed by checking if the state of the LeftButton is equal to the MouseButtonState enumeration value Pressed. If the button is pressed, a method is called which updates display elements in the sample.
We can detect a mouse event when the mouse moves over any component such as a label by using the mouseEntered () method and can be exited by using mouseExited () method of MouseAdapter class or MouseListener interface.
For the mouse-move message, check whether the left mouse button is down. If it is, recalculate the ellipse and repaint the window. In Direct2D, an ellipse is defined by the center point and x- and y-radii.
Store the position of the mouse click in the ptMouse variable. This position defines the upper left corner of the bounding box for the ellipse. Reset the ellipse structure. Call InvalidateRect. This function forces the window to be repainted. For the mouse-move message, check whether the left mouse button is down.
Here's an example (WPF):
public MainWindow()
{
InitializeComponent();
this.MouseMove += new MouseEventHandler(MainWindow_MouseMove);
}
void MainWindow_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
//do something
}
}
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