How to: Position Controls on Windows Forms

To position controls, use the Windows Forms Designer, or specify the Location property.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Working with Settings.

To position a control on the design surface of the Windows Forms Designer

To position a control using the Properties window

  1. Click the control you want to position.

  2. In the Properties window, type values for the Location property, separated by a comma, to position the control within its container.

    The first number (X) is the distance from the left border of the container; the second number (Y) is the distance from the upper border of the container area, measured in pixels.

    Note

    You can expand the Location property to type the X and Y values individually.

To position a control programmatically

  1. Set the Location property of the control to a Point.

    Button1.Location = New Point(100, 100)
    
    button1.Location = new Point(100, 100);
    
    button1.set_Location(new Point(100, 100));
    
    button1->Location = Point(100, 100);
    
  2. Change the X coordinate of the control's location using the Left subproperty.

    Button1.Left = 300
    
    button1.Left = 300;
    
    button1.set_Left(500);
    
    button1->Left = 300;
    

To increment a control's location programmatically

  • Set the Left subproperty to increment the X coordinate of the control.

    Button1.Left += 200
    
    button1.Left += 200;
    
    button1.set_Left(button1.get_Left() + 200);
    
    button1->Left += 200;
    

    Note

    Use the Location property to set a control's X and Y positions simultaneously. To set a position individually, use the control's Left (X) or Top (Y) subproperty. Do not try to implicitly set the X and Y coordinates of the Point structure that represents the button's location, because this structure contains a copy of the button's coordinates.

See Also

Tasks

Walkthrough: Arranging Controls on Windows Forms Using Snaplines

Walkthrough: Arranging Controls on Windows Forms Using a TableLayoutPanel

Walkthrough: Arranging Controls on Windows Forms Using a FlowLayoutPanel

How to: Set the Screen Location of Windows Forms

Reference

Windows Forms Controls by Function

Other Resources

Windows Forms Controls

Arranging Controls on Windows Forms

Labeling Individual Windows Forms Controls and Providing Shortcuts to Them

Controls to Use on Windows Forms