Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a button on my form. When I click it, I want a form to be opened exactly on the location where the button is. How to achieve this? Thanks.
Posted

In the form properties, set the StartPosition to Manual.
Then:
myForm f = new myForm();
f.Location = Cursor.Position;
f.Show();
This sets it to the current mouse position.
Or:
myForm f = new myForm();
f.Location = PointToScreen(myButton.Location);
f.Show();
This sets it to the button location - the button will be covered by the form.
 
Share this answer
 
You can do it one of two ways:

0) Handle the Left Mouse button Down event, and you can then retrieve mouse position at the time of the click. Then, you can open a form at that cursor position.

1) Handle the button click event and position the for at the top/left corner of the button being clicked.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900