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,
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.
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);
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