Begin by starting Visual Studio and creating a new Windows Forms project called ''CSharpEvents''. When the project has been created select the Form in the design area and add a Label control. In the properties panel change the name of the label to ''infoLabel''.
Begin by starting Visual Studio and creating a new Windows Forms project called ''CSharpEvents''. When the project has been created select the Form in the design area and add a Label control. In the properties panel change the name of the label to ''infoLabel''.
−Select the Form again and click on the lightening bolt button at the top of the properties panel. This will display a list of available events for the Form object. Scroll down the list and double click on the ''MouseClick'' event:
+Select the Form again and click on the lightning bolt button at the top of the properties panel. This will display a list of available events for the Form object. Scroll down the list and double click on the ''MouseClick'' event:
[[Image:c_sharp_mouseclick_event.jpg|Selecting a MouseClick event on a Windows Form]]
[[Image:c_sharp_mouseclick_event.jpg|Selecting a MouseClick event on a Windows Form]]
−Once the ''MouseClick'' event has been select by double clicking the code for the event will be displayed. This code will appear as follows:
+Once the ''MouseClick'' event has been selected by double clicking, the code for the event will be displayed. This code will appear as follows:
<pre>
<pre>
Now that we have a simple Form design and the outline of a MouseClick event handler the next step is to start interrogating the ''e'' event parameter object to learn a little more about the event that triggered to the call the ''Form1_MouseClick()'' event handler.
Now that we have a simple Form design and the outline of a MouseClick event handler the next step is to start interrogating the ''e'' event parameter object to learn a little more about the event that triggered to the call the ''Form1_MouseClick()'' event handler.
−Within the code outline for the methods type ''e.''. Visual Studio will then popup a list of available properties for this event object.
+Within the code outline for the methods, type ''e.'' followed by a dot (.). Visual Studio will then popup a list of available properties for this event object.
[[Image:c_sharp_mouse_click_properties.jpg|A list of properties available from a C# MouseClick event parameter]]
[[Image:c_sharp_mouse_click_properties.jpg|A list of properties available from a C# MouseClick event parameter]]
A number of useful properties are available to us in our C# code within this event handler. For the purposes of this example we are interesting in finding out which mouse button was pressed by the user and the X and Y co-ordinates. As such, we need to access the ''Button'', ''X'' and ''Y'' properties.
A number of useful properties are available to us in our C# code within this event handler. For the purposes of this example we are interesting in finding out which mouse button was pressed by the user and the X and Y co-ordinates. As such, we need to access the ''Button'', ''X'' and ''Y'' properties.
−The X and Y properties are easy to handle since they are simply integer values indicating where the moise pointer was in the form when the user clicked a mouse button. As such we can simplay take these values and display them in our ''infoLabel'' control:
+The X and Y properties are easy to handle since they are simply integer values indicating where the mouse pointer was in the form when the user clicked a mouse button. As such we can simply take these values and display them in our ''infoLabel'' control:
<pre>
<pre>
</pre>
</pre>
−After entering the above code press the '''F5''' to compile and run the application. Once tha program is running click at various points in the Form and watch the label change to report the co-ordinates of the click.
+After entering the above code press the '''F5''' to compile and run the application. Once the program is running, click at various points in the Form and watch the label change to report the co-ordinates of the click.
== Identifying which Mouse Button was Clicked ==
== Identifying which Mouse Button was Clicked ==
Amongst the properties of the MouseClick EventArgs object was a property named ''Button'' which may be accessed to identify which mouse button was clicked.
Amongst the properties of the MouseClick EventArgs object was a property named ''Button'' which may be accessed to identify which mouse button was clicked.
Exception encountered, of type "Error"
[fc765401] /index.php?diff=next&oldid=6851&title=C_Sharp_Events_and_Event_Parameters Error from line 434 of /var/www/techotopia/includes/diff/DairikiDiff.php: Call to undefined function each()
Backtrace:
#0 /var/www/techotopia/includes/diff/DairikiDiff.php(544): DiffEngine->diag()
#1 /var/www/techotopia/includes/diff/DairikiDiff.php(344): DiffEngine->compareSeq()
#2 /var/www/techotopia/includes/diff/DairikiDiff.php(227): DiffEngine->diffLocal()
#3 /var/www/techotopia/includes/diff/DairikiDiff.php(721): DiffEngine->diff()
#4 /var/www/techotopia/includes/diff/DairikiDiff.php(859): Diff->__construct()
#5 /var/www/techotopia/includes/diff/DairikiDiff.php(980): MappedDiff->__construct()
#6 /var/www/techotopia/includes/diff/TableDiffFormatter.php(194): WordLevelDiff->__construct()
#7 /var/www/techotopia/includes/diff/DiffFormatter.php(140): TableDiffFormatter->changed()
#8 /var/www/techotopia/includes/diff/DiffFormatter.php(82): DiffFormatter->block()
#9 /var/www/techotopia/includes/diff/DifferenceEngine.php(881): DiffFormatter->format()
#10 /var/www/techotopia/includes/diff/DifferenceEngine.php(797): DifferenceEngine->generateTextDiffBody()
#11 /var/www/techotopia/includes/diff/DifferenceEngine.php(728): DifferenceEngine->generateContentDiffBody()
#12 /var/www/techotopia/includes/diff/DifferenceEngine.php(662): DifferenceEngine->getDiffBody()
#13 /var/www/techotopia/includes/diff/DifferenceEngine.php(632): DifferenceEngine->getDiff()
#14 /var/www/techotopia/includes/diff/DifferenceEngine.php(453): DifferenceEngine->showDiff()
#15 /var/www/techotopia/includes/page/Article.php(797): DifferenceEngine->showDiffPage()
#16 /var/www/techotopia/includes/page/Article.php(508): Article->showDiffPage()
#17 /var/www/techotopia/includes/actions/ViewAction.php(44): Article->view()
#18 /var/www/techotopia/includes/MediaWiki.php(490): ViewAction->show()
#19 /var/www/techotopia/includes/MediaWiki.php(287): MediaWiki->performAction()
#20 /var/www/techotopia/includes/MediaWiki.php(714): MediaWiki->performRequest()
#21 /var/www/techotopia/includes/MediaWiki.php(508): MediaWiki->main()
#22 /var/www/techotopia/index.php(41): MediaWiki->run()
#23 {main}