C # hold mouse click

I have a mousemove event that takes a cursor position and outputs it to two labels (X and Y), the value changes dynamically on hover. I have a mousedown event, which when clicked, the same values ​​are displayed in the text box. How can I combine the mousedown and mousemove events so that when you hover and hold the mouse button, the value of the text field changes dynamically as you move.

+1
source share
3 answers

You can poll the mouse buttons in the Move event handler, that is:

void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) { String tipText = String.Format("({0}, {1})", eX, eY); trackTip.Show(tipText, this, e.Location); } } 
+5
source

Track the mouse and mouse events to set a variable that determines whether the mouse button is pressed (i.e., set down down is not set by the mouse), and then just check this variable in mouse_move

see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousebuttons.aspx for an example

+2
source

Use

  private void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { } } 

like this, and in the second if you will have a condition when your mosue moves and . The left mouse button does not work.

+1
source

Source: https://habr.com/ru/post/1434137/


All Articles