简体   繁体   English

调整表单大小时调整组件大小

[英]Resize components when the form is resized

Can I resize components automatically when a form is resized? 调整表单大小后,是否可以自动调整组件大小? Not in code, but in the form designer. 不是代码,而是表单设计器。

I'm trying to create an 'abstract form' for me and the others developers use it as an 'inherited form'. 我正在尝试为我创建一个“抽象形式”,其他开发人员将其用作“继承形式”。

I am drawing the form with four panels: top and bottom, and both sides. 我正在用四个面板绘制表单:顶部和底部,以及两侧。 And I need when the form is resized, the panels will be resized too. 我需要调整表单大小时,面板也要调整大小。

You can set the Anchor property of components. 您可以设置组件的Anchor属性。 the Anchor property defines how a control is automatically resized as its parent control is resized. Anchor属性定义控件在调整其父控件大小时如何自动调整大小。 Anchoring a control to its parent control ensures that the anchored edges remain in the same position relative to the edges of the parent control when the parent control is resized. 将控件锚定到其父控件可确保在调整父控件的大小时,锚定边缘相对于父控件的边缘保持在相同位置。

You can anchor a control to one or more edges of its container. 您可以将控件锚定到其容器的一个或多个边缘。 For example, if you have a Form with a Button whose Anchor property value is set to Top and Bottom , the Button is stretched to maintain the anchored distance to the top and bottom edges of the Form as the Height of the Form is increased. 例如,如果您有一个带有按钮的“表单”,其“锚点”属性值设置为“ Top和“ Bottom ,则随着“表单高度”的增加,将拉伸按钮以保持到表单顶部和底部边缘的固定距离。

To do that programmatically use the code like 为此以编程方式使用如下代码

control1.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left;

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor%28v=vs.110%29.aspx http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor%28v=vs.110%29.aspx

尝试使用myControl.Dock = DockStyle.Fill;

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

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