Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering MouseDown and MouseMove on Form

Tags:

c#

How and where can I register a mouse event on a form. When I doubleclick on the form it'll generate the Form_Load event for me and I can add code into there. However when I add something like

private void Form1_MouseDown(object sender, MouseEventArgs e{

Console.WriteLine("mouse down")

}

However when I do a mousedown event on the form I don't get anything on the console. I know something is missing where I register the event to the form or something of the sort. Any ideas?

Thanks,

like image 240
user541597 Avatar asked Dec 22 '25 23:12

user541597


2 Answers

In the designer view, select the form and then in the properties window, click the little lightning bolt (events).

Here you're able to select which delegate method is called for which event. If you haven't created the method already, just double click the empty space next to an event and it will generate the code for you.

like image 190
blizz Avatar answered Dec 24 '25 14:12

blizz


If you are using VS.net then you should find all the events in the property panel. Just pick the ones you want.

If you want to grammatically register an event then the code would looks like:

Form1.Click += new MouseEventHandler(Form1_MouseDown);

in order to unregister it's

Form1.Click -= new MouseEventHandler(Form1_MouseDown);
like image 41
Samy Arous Avatar answered Dec 24 '25 13:12

Samy Arous



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!