gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:32:46 29 4
gpt4 key购买 nike

在 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com