调整面板大小以适合 Windows 窗体中包含的元素
我正在创建一个可折叠面板元素,它本质上是一个带有按钮元素和按钮下方的面板元素的面板元素。单击该按钮会使相邻面板显示 Visible = false
。当子面板设置为不可见时,我想调整包含面板的大小。
我通过将 Size
属性设置为可见元素(按钮或按钮和子面板)的宽度和高度的总和来手动完成此操作。
我很想知道如果有一种方法可以强制调整包含面板的大小,而无需手动调用 Size
。
我想我正在寻找属性 Dock=Fill
的逆属性,它根据元素包含元素的大小自动调整元素的大小。
提前致谢。
I am creating a collapsible panel element, which would essentially be a panel element with a button element and a panel element below the button. Clicking the button causes the neighboring panel to have Visible = false
. I would like to resize the containing panel when the child panel is set to invisible.
I have done this manually, by setting the Size
property to be the sum of the widths and heights of the visible elements (either the button or the button and the child panel.)
I am curious to know though if there was a way to force the resize of the containing panel without manually calling Size
.
I guess I'm looking for the inverse of the property Dock=Fill
, which automatically resizes elements based on the size of their containing element.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚尝试了 isspiro 给出的答案。您不需要需要删除和添加该控件。设置
Visible
可以。这取决于您何时执行布局。如果 panel2 在 panel1 之前执行布局,则 panel2 将不会调整大小。为了使其更容易,请改用父级PerformLayout
。它的使用方式如下:
I just tried the answer given by ispiro. You dont need to remove and add the control. Setting
Visible
can work. It depends on when you perform the layout. If panel2 performs the layout before panel1, panel2 will not resize. To make it easier, use the parentsPerformLayout
instead.It's used like this:
怎么样:
然后不要更改可见性,而是执行以下操作:
当您想要将其恢复时:
(panel1 是后面板)
How about doing:
and then instead of changing the visibility, do this:
and when you want to bring it back:
(panel1 is the back-panel)