Home and Learn: C# NET Course
You can see what event are available for a particular control in the Properties area.
In Design View, click on your Form1 to select it, instead of the button. To see what events are available for the Form itself, click the lightning bolt at the top of the Properties area, as in the image below:
When you click the lightning bolt, you'll see a list of events appear:
You've already met the Load event, so we won't cover it here. But notice how many events there are.
Locate the MouseDown event on the list. Now double click the word "MouseDown". You should see a code stub appear:
In between the round brackets, there is still a sender object. But notice the new argument:
The letter "e" is the default variable name. The type of variable belongs to the MouseEventArgs. You can see what this does by typing the letter "e", then a full stop (period). You should see the IntelliSense list appear:
The list is displaying the properties and methods available to the e variable. One of these is the Button property.
We can use an if statement to check which mouse button was clicked. Add this
to your code:
Run your programme and click either of your mouse buttons on the form. You should see a message box display.
Buy the Book of this Course
Email us: enquiry at homeandlearn.co.uk