Export (0) Print
Expand All

Form.Size Property

Gets or sets the size of the form.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[LocalizableAttribute(false)] 
public Size Size { get; set; }
/** @property */
public Size get_Size ()

/** @property */
public void set_Size (Size value)

public function get Size () : Size

public function set Size (value : Size)

Not applicable.

Property Value

A Size that represents the size of the form.

This property allows you to set both the height and width (in pixels) of the form at the same time instead of setting the Height and Width properties individually. If you want to set the size and location of a form, you can use the DesktopBounds property to size and locate the form based on desktop coordinates or use the Bounds property of the Control class to set the size and location of the form based on screen coordinates.

NoteNote:

The maximum value of this property is limited by the resolution of the screen on which the form runs. The value cannot be greater than 12 pixels over each screen dimension (horizontal + 12 and vertical + 12).

NoteNote:

On Pocket PC devices, you can create a resizable window by setting FormBorderStyle to None and removing any MainMenu control. On SmartPhone devices, you can never resize a Form - it will always fill the entire screen.

The following code example demonstrates how to create a form that is displayed with an opacity level of 75 percent. The example code creates a new form that is positioned in the center of the screen with an Opacity property set to change the opacity level of the form. The example code also sets the Size property to provide a larger sized form than the default size of the form. This example requires that the method defined in this example is called from another form in an event handler or other method.

private void CreateMyOpaqueForm()
{
   // Create a new form.
   Form form2 = new Form();
   // Set the text displayed in the caption.
   form2.Text = "My Form";
   // Set the opacity to 75%.
   form2.Opacity = .75;
   // Size the form to be 300 pixels in height and width.
   form2.Size = new Size(300,300);
   // Display the form in the center of the screen.
   form2.StartPosition = FormStartPosition.CenterScreen;

   // Display the form as a modal dialog box.
   form2.ShowDialog();
}

private void CreateMyOpaqueForm()
{
    // Create a new form.
    Form form2 = new Form();

    // Set the text displayed in the caption.
    form2.set_Text("My Form");

    // Set the opacity to 75%.
    form2.set_Opacity(0.75);

    // Size the form to be 300 pixels in height and width.
    form2.set_Size(new Size(300, 300));

    // Display the form in the center of the screen.
    form2.set_StartPosition(FormStartPosition.CenterScreen);

    // Display the form as a modal dialog box.
    form2.ShowDialog();
} //CreateMyOpaqueForm

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft