Resize in Windows Forms controls along with form resize

∥☆過路亽.° 提交于 2019-12-01 04:09:38

问题


I have a few controls (group boxes, tables, gridview, etc.) in my C# Windows Forms application, and I would like to scale them based on screen width/height.

For example, the screen starts at, let's say, 640x480 and then it gets maximized to 1920x1200.

I want to be able to increase the width/height of the controls so they look the exact same after the window gets re-sized.

What is the best way to do that, without setting every width/height property manually?


回答1:


What is the best way to do that, without setting every width/height property manually?

Instead of specifying width and height, you can use the Anchor and Dock properties to have controls scale based on their containing elements.

Alternatively, you can use TableLayoutPanel or FlowLayoutPanel to arrange your controls.




回答2:


I believe you want the control's Anchor property.

As the name implies, this property forces the control to anchor itself in a relative or absolute position within the parent form or control. This property has four values that can be turned on or off:

Top -- Indicates that the control should keep its top edge stationary in respect to the parent form (or control) top edge.
Bottom -- Indicates that the control should keep its bottom edge stationary in respect to the parent form (or control) bottom edge.
Left -- Indicates that the control should keep its left edge stationary in respect to the parent form (or control) left edge.
Right -- Indicates that the control should keep its right edge stationary in respect to the parent form (or control) right edge.

IIRC, you want to select all the controls on the form using Ctrl+A, and then setting the anchor property to top, bottom, left, and right.



来源:https://stackoverflow.com/questions/16403469/resize-in-windows-forms-controls-along-with-form-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!