Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Hold down mouse event

I have a mousemove event that takes the position of the cursor and outputs it to two labels (X and Y), the value dynamically changes as I hover around. I have a mousedown event that when clicked, the same values are outputted to a textbox. How can I combine the mousedown and mousemove events so that when I hover AND hold down the mouse button, the textbox value dynamically changes as I move.

like image 994
Jack Avatar asked Apr 25 '26 03:04

Jack


2 Answers

You can interrogate the mouse buttons in your Move event handler, i.e. :

void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left) {
        String tipText = String.Format("({0}, {1})", e.X, e.Y);
        trackTip.Show(tipText, this, e.Location);
    }
}
like image 155
Lazarus Avatar answered Apr 26 '26 15:04

Lazarus


Track the mouse down and mouse up events to set a variable determining whether or not the mouse button is pressed (ie set in down unset in mouse up) 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

like image 24
Bob Vale Avatar answered Apr 26 '26 17:04

Bob Vale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!