简体   繁体   中英

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. 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.

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:

  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

See this for a guide on how to use them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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