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

前端之家收集整理的这篇文章主要介绍了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;

猜你在找的C#相关文章