There are two things to address.
First, I think you'll have some trouble with that code as PointToClient is meant to work with cursor location relative to the screen.
You might want this instead (which will work on multiple monitors, from any control):
private void TestApp_MouseClick(object sender, MouseEventArgs e)
{
Point p2 = PointToClient(Cursor.Position);
string coords = string.Format("({0},{1})", p2.X, p2.Y);
Clipboard.SetText(coords);
}
Secondly, you'll need an event handler for each of the controls on your form, or one event handler to handle them all. Go with the second one...here's how:
- Go to your form designer, click in the form (not on a control) and press CTRL-A. This will select all controls.
- In your properties window, click on the lightning bolt to see the events.
- Click in the MouseClick event to get the drop down. It should contain the name of the function you've already written.
- Select the function you've written!
If you want to see what Visual Studio did for you, go to the Form.Designer.cs file in Project Explorer. It will have added a line like the following for each of your controls:
this.button1.MouseClick += new System.Windows.Forms.MouseEventHandler(this. TestApp_MouseClick);
Basically, it wires up an event handler for you when you select a method from the drop down.
Cheers!