Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 732
RCIX Avatar asked Nov 30 '09 01:11

RCIX


People also ask

How do you arrange controls in a form?

Do one of the following: On the Arrange tab, in the Table group, click the layout type you want for the new layout (Tabular or Stacked). Right-click the selected controls, point to Layout, and then click the layout type you want for the new layout.

How do I center an object in Windows form?

From the Format menu, choose Center in Form. From the cascading menu, choose one of the following: Horizontally.

How do I center a Windows form in C#?

To achieve this select the form you want to start in the center screen then go to properties and set the Startposition property to CenterScreen.

Is it possible to resize a control within the form design window?

You can resize individual controls, and you can resize multiple controls of the same or different kind, such as Button and GroupBox controls.


1 Answers

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 alt text

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.

like image 82
Eric Packwood Avatar answered Sep 24 '22 09:09

Eric Packwood