C#获取窗体上的控件的位置 [英] C# Get a control's position on a form
问题描述
有什么办法来检索的形式,当控制可能是其他控件内部(如面板)控件的位置?
Is there any way to retrieve a control's position in a form, when the control may be inside other controls (like Panels)?
控件左和Top属性给了我只有它的位置在它的父控件,但如果我的控制里面有五名嵌套板是什么,我需要它的在表单上持何立场?
The control's Left and Top properties gives me only it's position within it's parent control, but what if my control is inside five nested panels, and I need it's position on the form?
简单的例子:
按钮btnA位于面板内坐标(10,10)PNLB。
该面板PNLB位于表格里面FRMC坐标(15,15)。
The button btnA is located on coordinates (10,10) inside the panel pnlB.
The panel pnlB is located on coordinates (15,15) inside the form frmC.
我要btnA对FRMC位置,这是(25,25)。
I want btnA's location on frmC, which is (25,25).
我能得到这个位置?
推荐答案
我通常将 PointToScreen
和 PointToClient
:
Point locationOnForm = control.FindForm().PointToClient(
control.Parent.PointToScreen(control.Location));
这篇关于C#获取窗体上的控件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!