微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐