Things You'll Need:
- Microsoft Visual C# 2008 Express (free)
-
Step 1
Note: This article assumes you have installed Microsoft Visual C# 2008 Express Edition. You may download it for free from here:
http://www.microsoft.com/express/download/
Open Microsoft Visual C#. Click on "Project..." to the right of Create in the Recent Projects area of the Start Page.
The New Project window will open. Click on "Windows Forms Application", enter a Name, and click OK.
By default, the only form in the project will be called "Form1" and you will be in Design mode for that form. -
Step 2
The form will be displayed in the design view.
-
Step 3
Open the Properties window for the form. If you do not see the Properties window, go to the toolbar and select View->Properties Window.
-
Step 4
In the toolbar for the Properties window, click the button with the lightning bolt icon on it. This will show you the events for the form.
Find the MouseClick event and double click the empty cell to the right. -
Step 5
You will now be in the Form1_MouseClick event.
Enter the following text:
MessageBox.Show("X = " + e.X + ", Y = " + e.Y);
This will cause a MessageBox to appear and the X and Y coordinates will be displayed in the box. Note that the second argument to the
MouseClick event is of the type MouseEventArgs. This object has X and Y properties that return the X and Y coordinates in pixels. -
Step 6
Go up to the toolbar and run the program by clicking on the Start Debugging (f5) play button.
NOTE: If you got any kind of error after clicking the play button, you probably made a syntax error when typing the code. Reread the code
until you find and correct the error and try again. -
Step 7
The form will take a moment and then pop up.
Click somewhere on the form and the message box will pop-up and tell you exactly where you clicked. Cool, huh?















