NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Resizing Controls on Win Forms

You can resize controls at run time by specifying the Size and Location in a Rectangle object in code and assigning the Rectangle to the Bounds property of the control.

To size a control programmatically

  1. Open your form in your code editor.
  2. Type code to create a private method with a Rectangle object and a control. For example:
    [Visual Basic]
    Private Sub MakeSizedButton()
       Dim rect1 as Rectangle
       Dim button1 as Button
    
       Set rect1 = new Rectangle
    'Use the SetBounds method to set the X,Y,Width, and Height of the Rectangle.
       rect1.SetBounds(75, 23, 100, 50)
    [C#]
    private void MakeSizedButton() {
        Rectangle rect1 = new Rectangle (50, 100, 75, 23);
  3. Add code to this private method to set the Bounds property of the Button control equal to the dimensions of the Rectangle object. For example:
    [Visual Basic]
       Set button1.Bounds = rect1
    End Sub
    [C#]
        button1.Bounds = rect1;
    }
    Note   Alternatively, you can also use the Size and Location properties to independently specify the size and location of the control respectively. For more information about the Location property, see Positioning Controls on Win Forms.
  4. If you do not have a constructor for the form, create one. Add the following code after the InitForm method is called in this constructor:
    [Visual Basic]
    MakeSizedButton
    [C#]
    MakeSizedButton();

See Also

Control Manipulation on Win Forms | Controls by Category | Adding Controls to Win Forms | Anchoring Controls on Win Forms | Docking Controls on Win Forms | Layering Objects on Win Forms | Setting the Tab Order on Win Forms | Working with Individual Controls | Controls You can Use on Win Forms | Control Technologies and Where to Use Them | Win Form Controls by Function