加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 获取Groupbox真正可用的区域

发布时间:2020-12-15 05:37:33 所属栏目:百科 来源:网络整理
导读:在 Windows窗体中,当我将标签控件放在组框内的Y = 0时,标签与组框顶部的标题文本相交. 如何获得Groupbox中的可用区域,即不受框的标题文本阻碍的区域? 设置control.Y = groupBox.Padding.Top不起作用.并且Groupbox.ClientRectangle也不考虑文本. 编辑:有一
在 Windows窗体中,当我将标签控件放在组框内的Y = 0时,标签与组框顶部的标题文本相交.

如何获得Groupbox中的可用区域,即不受框的标题文本阻碍的区域?

设置control.Y = groupBox.Padding.Top不起作用.并且Groupbox.ClientRectangle也不考虑文本.

编辑:有一个简单的黑客来获得内部矩形:只需在GroupBox中放置一个Label,并将其Dock属性设置为Fill.然后,您可以从Panel获取相关信息(上/下/左/右),或直接使用面板添加您的子控件.
但是,我仍然想知道如何在没有这些黑客的情况下获得这些坐标.

解决方法

尝试使用 DisplayRectangle属性:

The DisplayRectangle property returns the client rectangle of the display area of the control. For the base control class,this is equal to the client rectangle. However,inheriting controls might want to change this if their client area differs from their display area. The display rectangle is the smallest Rectangle that encloses a control and is used to lay out controls.

例:

label1.Location = groupBox1.DisplayRectangle.Location;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读