在 ac# 表单上调整组件大小
通常在 java 中,如果您有某种布局管理器,那么当您调整页面大小时,该面板中的组件将相应地调整大小。我认为我的应用程序缺少某种布局管理器来控制调整大小,因为目前一切都是静态的
有没有办法让它根据表单大小的变化调整大小?假设用户使页面更大,然后组件进行调整等等。
谢谢
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. 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.NET 也有布局管理器。
就我个人而言,我更喜欢
TableLayoutPanel
对于我的 WinForms 应用程序。一旦您布局表格(使用静态/动态大小的行/列的组合),您就可以将子控件添加到表格单元格中。添加控件后,您可以将控件停靠或锚定到单元格,以便在调整窗口大小时自动调整它们。
.NET has layout managers as well.
Personally, I prefer the
TableLayoutPanel
for my WinForms apps.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:
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.
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 属性,这将导致控件在窗口大小调整时进行相应调整。
In Windows Forms you make use of the Control.Anchor property, which will cause the control to adjust accordingly when the window resizes.
要对 Windows 表单执行此操作,您可以使用 Anchor< /a> 和 Dock 属性控件
请参阅 this 有关如何使用它们的指南
To do this with windows forms you use the Anchor and Dock properties of the control
See this for a guide on how to use them