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

标签 c# winforms

在 Windows 窗体中,当我将标签控件放置在组框内的 Y=0 处时,标签会与组框顶部的标题文本相交。

如何获得 Groupbox 中的可用区域,即未被框的标题文本遮挡的区域?

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

Explanation

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

最佳答案

尝试使用 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# - 获取 Groupbox 的真正可用区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14346511/

相关文章:

c# - 什么属性定义段落或表格的边距?

c# - ProcessCmdKey - 等待 KeyUp?

c# - 阻止 DomainUpDown 控件中的粘贴事件

c# - 如何使 winforms 控件随窗口调整大小?

c# - 使用 Asp.net Identity 删除角色

c# - 一个参数的多个构造函数

winforms - 如何处理因在 DataGrid 中的行之间双击而导致的异常?

.net - 如何查看部分类的两边

c# - 识别 CheckedListBox 项已被选中

c# - Windows 窗体 C# 通过代码更改用户控件