Resizing Controls on Windows Forms
This documentation is archived and is not being maintained.

Resizing Controls on Windows Forms

Visual Studio .NET 2003

To resize controls, use the Windows Forms Designer, or specify the Size and Location of a Rectangle object in code and use the rectangle as the basis for the size of the control.

To resize a control in the Windows Forms Designer

  • Click the control to be resized and drag one of the eight sizing handles.
    Note   Select the control and press the ARROW keys while holding down the SHIFT key to resize it using the keyboard. Press the ARROW keys while holding down the SHIFT and CTRL keys to resize it with great precision.

To size a control programmatically

  1. Enter code to create a private method with a Rectangle object and a control. For example:
    ' Visual Basic
    Private Sub MakeSizedButton()
       Dim rect1 as New Rectangle(50, 100, 75, 23)
       Dim Button1 as New Button()
    End Sub
    
    // C#
    private void MakeSizedButton() 
    {
       Rectangle rect1 = new Rectangle (50, 100, 75, 23);
       Button button1 = new Button();
    }
    
    // C++
    private:
       void MakeSizedButton()
       {
          Rectangle rect1 (50, 100, 75, 23);
          Button *button1 = new Button();
       }
    
  2. Add code to the end of this private method to set the Bounds property of the Button control equal to the dimensions of the Rectangle object. For example:
    ' Visual Basic
       Button1.Bounds = rect1
    
    // C#
       button1.Bounds = rect1;
    
    // C++
       button1->Bounds = rect1;
    
    Note   Alternately, you can also set the Size and Location properties of your control to independently specify the size and location of the control respectively. For more information about the Location property, see Positioning Controls on Windows Forms.
  3. If you do not have a constructor for the form, create one. Add the following code after the InitializeComponent() method is called in this constructor:
    ' Visual Basic
    MakeSizedButton()
    
    // C#
    MakeSizedButton();
    
    // C++
    MakeSizedButton();
    

To standardize the layout of the user interface of your Windows application, you can size groups of controls with a single command.

To resize multiple controls on a form

  1. Select the controls you want to align such that the last control you select is the primary control to which the others should be aligned.

    The primary control has dark-colored sizing handles around its perimeter, while all other selected controls have light-colored sizing handles. To select multiple controls, click each one in turn while holding down the SHIFT key.

  2. On the Format menu, point to Make Same Size, and then click one of the four choices available. The first three commands change the dimensions of the controls to match the primary control.

See Also

Windows Forms Controls | Controls by Category | Arranging Controls on Windows Forms | Labeling Individual Windows Forms Controls and Providing Shortcuts to Them | Controls You Can Use on Windows Forms | Windows Forms Controls by Function | Creating Windows Forms

Show:
© 2016 Microsoft