确定表单的打开位置. [英] Determining opening location of a form.
本文介绍了确定表单的打开位置.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单上有一个按钮.当我单击它时,我希望在按钮所在的位置完全打开一个表单.如何实现呢?
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.
推荐答案
在表单属性中,将StartPosition设置为Manual.
然后:
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.
您可以通过以下两种方式之一进行操作:
0)处理鼠标左键按下事件,然后您可以在单击时检索鼠标位置.然后,您可以在该光标位置打开一个表单.
1)处理按钮单击事件,并将for放置在要单击的按钮的左上角.
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.
这篇关于确定表单的打开位置.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文