C#获取窗体上的控件的位置

编程入门 行业动态 更新时间:2024-10-12 10:22:33
本文介绍了C#获取窗体上的控件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有什么办法来检索的形式,当控制可能是其他控件内部(如面板)控件的位置?

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#获取窗体上的控件的位置

本文发布于:2023-10-08 01:11:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471071.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   控件   位置

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!