简体   繁体   English

使用C#将控件锚定到不是窗体的父控件

[英]Anchoring controls to a parent control that is not a form using C#

I have a panel being used like a subform. 我有一个像子窗体一样使用的面板。 What I would like is to restrict the panel to some maximum size. 我想将面板限制为最大尺寸。 When the form is maximized or resized, the subform is resized only to some maximum height and width. 当表单最大化或调整大小时,子表单仅调整为最大高度和宽度。 Couldn't find a property to limit the size of the panel so I did it manually by handling its resize event. 找不到限制面板大小的属性,因此我通过处理其resize事件手动完成了操作。 That's okay because it's only one control. 没关系,因为它只是一个控件。

The problem is with the controls inside the panel. 问题出在面板内部的控件上。 I thought it was simply a matter of anchoring some of the controls to the panel. 我认为这仅仅是将某些控件固定到面板上的问题。 Wrong! 错误! It looks like they're being anchored to the form. 看起来他们已经被固定在表格上了。 Any solultions besides manually resizing all the controls? 除了手动调整所有控件的大小以外,还有其他解决方法吗?

Make sure that the controls have been added to the Controls collection of the Panel. 确保已将控件添加到面板的控件集合中。 If they have, your scenario should work as expected. 如果有,您的方案应按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM