简体   繁体   English

在AC#表单上调整componenet的大小

[英]Resizing componenets on a c# form

typically in java if you have a layout manager of somesort, when you resize the page then the components in that panel will resize accordingly. 通常在Java中,如果您具有某种布局管理器,则在调整页面大小时,该面板中的组件将相应地调整大小。 I think my app is missing some sort of layout manager to control resizing as at the moment everything is just static 我认为我的应用程序缺少某种布局管理器来控制大小调整,因为目前一切都只是静态的

Is there a way to make it resize on the changing of the form size? 有没有一种方法可以根据表单大小的变化来调整大小? say the user makes the page bigger, then the componenets adjust and so on. 说用户使页面变大,然后组件进行调整,依此类推。

Thanks 谢谢

.NET has layout managers as well. .NET也具有布局管理器。

Personally, I prefer the TableLayoutPanel for my WinForms apps. 就个人而言,我更喜欢将TableLayoutPanel用于WinForms应用程序。

Once you layout the Table (using a combination of static/dynamic sized rows/columns) you add your child controls to the table cells. 布置完表格(使用静态/动态大小的行/列的组合)后,您就可以将子控件添加到表格单元格中。 Once you add your controls, you can dock or anchor the controls to the cell so that they are automatically adjusted when the window is re-sized. 添加控件后,可以将控件停靠或锚定到单元格,以便在调整窗口大小时自动调整它们。

Two main options: 两个主要选项:

  1. Anchoring . 锚定 Set your control to "anchor" to the sides of your form. 将控件设置为“锚定”到窗体的两侧。 This means that if the form resizes, the control will stay a constant distance from that side. 这意味着,如果调整窗体的大小,则控件将与该边保持恒定的距离。 So, if you anchor Top, Left and Right, then your control will stay in the same position, but resize horizontally with the width of the form. 因此,如果您锚定“顶部”,“左侧”和“右侧”,则控件将保持在同一位置,但会根据表单的宽度水平调整大小。 Play with it. 玩吧。 It'll be obvious. 这很明显。

  2. Docking . 对接 Set your control to "dock" to a side of the form, or the center. 将控件设置为“停靠”到表单的一侧或中心。 This is usually done with containers, and it will make the widget take up that entire portion of the form no matter how large it gets. 通常,这是使用容器完成的,这将使窗口小部件占据表单的整个部分,无论它变大了多少。

在Windows窗体中,您可以使用Control.Anchor属性,该属性将导致控件在调整窗口大小时相应地进行调整。

To do this with windows forms you use the Anchor and Dock properties of the control 若要使用Windows窗体执行此操作,请使用控件的AnchorDock属性

See this for a guide on how to use them 请参阅以获取有关如何使用它们的指南

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

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