Align controls to the center of a form in Windows Forms designer

本秂侑毒 提交于 2019-12-08 19:32:15

问题


This is something that's been driving me up the wall: how can I get the Windows Forms designer to provide pixel snapping for the horizontal and vertical centers of the form I'm working on?


回答1:


Visual Studio provides a number of tools to assist in aligning groups and sizing groups of controls in a form. These features are accessed using the layout toolbar. To display the layout toolbar right click on any part of the standard Visual Studio Toolbar and select Layout from the drop down menu. The resulting toolbar will appear as follows:

The Visual Studio Layout Toolbar

Select a group of components and click on the various buttons in the toolbar to see the effect. For example, all the controls can be left or right aligned and resized to the same size, width or height. It is also possible to equally space the controls, and then increase or decrease the spacing used to separate the controls. It is also possible place controls on top of one another and change which control appears on top of the stack (this can also be done in Visual Basic code using the BringToFront() and SendToBack() methods of the respective controls).

All together, the selection of controls allows just about any uniform layout to be achieved from a group of controls in a form.

http://www.techotopia.com/index.php/Designing_Forms_in_Visual_Studio

5th and 6th icon from the right end will do the trick for you:

  • Center Horizontally
  • Center Vertically

Not quite automatic, but still works.



来源:https://stackoverflow.com/questions/1817473/align-controls-to-the-center-of-a-form-in-windows-forms-designer

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