Since every form is derived from the Form class, which itself is derived from the Control class, they have all the properties of the Control and Form base classes, of which there are about one hundred. Many of the most commonly used properties are listed in Table 5-1. These properties can either be set in Visual Studio .NET at design time or set programmatically at runtime.
Table 5-1. Form properties
Property |
Value type |
Description |
---|---|---|
AcceptButton |
IButtonControl |
Gets or sets the button on a form that is clicked when the user presses Enter, irrespective of which control actually has focus. |
ActiveForm |
Form |
Static property (shared in VB.NET) that gets the currently active
form. Returns |
ActiveMdiChild |
Form |
Gets currently active MDI child. Returns |
AutoScroll |
Boolean |
If set |
BackColor |
Color |
Gets or sets the background color. |
CancelButton |
IButtonControl |
Gets or sets the button on a form that is clicked when the user presses Escape, irrespective of which control actually has focus. |
ClientSize |
Size |
Gets or sets the size of the area of the form excluding the borders and titlebar. |
ControlBox |
Boolean |
Gets or sets a value indicating if the system menu can be displayed
and if the Close button (X) is displayed on the right end of the
titlebar. The system menu is exposed by clicking on the titlebar icon
if the Icon property is set, or by right-clicking on the titlebar if
the Icon property is not set. The default is |
DesktopBounds |
Rectangle |
Gets or sets the size and location of the form on the Windows desktop, using pixel-based desktop coordinates. |
DesktopLocation |
Point |
Gets or sets the location of the form on the Windows desktop, using pixel-based desktop coordinates. Differs from the Location property in that it takes into account the taskbar, if any. |
DialogResult |
DialogResult |
Gets or sets the return value from a form or dialog box displayed modally. Legal values are members of the DialogResult enumeration. This is covered in detail in Chapter 6. |
FormBorderStyle |
FormBorderStyle |
Gets or sets the border style. In addition to appearance, the FormBorderStyle dictates whether the form will be resizable. The possible values of the FormBorderStyle enumeration are listed in Table 5-2. |
Height |
Integer |
Gets or sets the height of the form in pixels. |
Icon |
Icon |
Gets or sets the icon for the form. The icon is displayed in the
control box of the form (if ControlBox property is set to
|
MaximizeBox |
Boolean |
Gets or sets a value indicating if maximize button will be displayed
in upper right corner of form on the titlebar. The default is
|
MinimizeBox |
Boolean |
Gets or sets a value indicating if minimize button will be displayed
in upper right corner of form on the titlebar. Default is
|
Modal |
Boolean |
Read-only value indicating if form is displayed modally using the ShowDialog method. |
Opacity |
double |
Gets or sets the opacity level of the form, its border, and its controls, which can range between 1.00 (100 percent), the default value, and 0. If value is 0, the form is completely invisible and cannot be clicked on. |
ShowInTaskBar |
Boolean |
Gets or sets value indicating if the form Text property is displayed
in the Windows taskbar. Default is |
Size |
Size |
Gets or sets both the height and width of the form. |
SizeGripStyle |
SizeGripStyle |
Gets or sets one of three possible values that indicate the style of
the sizing grip displayed at the lower-right corner of a form. The
valid values are |
StartPosition |
FormStartPosition |
Gets or sets the starting position of the form. Legal values of the FormStartPosition enumeration are listed in Table 5-3. |
TopLevel |
Boolean |
Gets or sets value indicating the form has no parent form ( i.e., if
|
TopMost |
Boolean |
Gets or sets value indicating that the form is displayed on top of all the other forms, even if it is not the active form. Typically used for modeless dialog boxes that should always be visible, such as alerts. |
Width |
Integer |
Gets or sets the width of the form in pixels. |
WindowState |
FormWindowState |
Gets or sets value of enumeration that indicates the state of the
form. Valid values are |
Table 5-2. FormBorderStyle enumeration values
Value |
Description |
---|---|
Fixed3D |
Nonresizeable, 3D border. |
FixedDialog |
Nonresizeable, dialog-style border. |
FixedSingle |
Nonresizeable, single line border. |
FixedToolWindow |
Nonresizeable, tool window border. |
None |
No border. |
Sizable |
Default value. Standard resizable border. |
SizableToolWindow |
Resizable, tool window border. |
Table 5-3. FormStartPosition enumeration values
Value |
Description |
---|---|
CenterParent |
Center form within parent form. |
CenterScreen |
Center form within current display. |
Manual |
Location and size of form dictates its starting position. |
WindowsDefaultBounds |
Form at Windows default location with bounds determined by Windows default. |
WindowsDefaultLocation |
Form at Windows default location with dimensions specified in form's constructor. |