Form Properties
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.
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 null (Nothing in VB.NET) if there is no active form. |
ActiveMdiChild |
Form |
Gets currently active MDI child. Returns null (Nothing in VB.NET) if there is no active form. Allows operations on MDI child forms from MDI parent form, or determination if any open MDI child forms. |
AutoScroll |
Boolean |
If set true, the default, scrollbars will automatically display if any controls are outside the form's client region. |
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 true. |
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 true) and in the taskbar (if ShowInTaskbar is set to true). |
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 true. If true, FormBorderStyle must be either FixedSingle, Sizable, Fixed3D, or FixedDialog. When the form is maximized, the maximize button automatically becomes a restore button. |
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 true. If true, FormBorderStyle must be either FixedSingle, Sizable, Fixed3D or FixedDialog. When the form is maximized, the minimize button automatically becomes a restore button. |
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 true. |
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 Auto, which displays the sizing grip as if the form is opened modally, Hide, which hides the sizing grip, and Show, which always shows the sizing grip. |
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 true, it is either an SDI form or an MDI parent form). The default is true. This property works in concert with the Parent property. A non-top-level TopLevel form just disappears if the Parent property is not set to a value. Also, an exception is raised if you try to set TopLevel to true without first setting Parent to null. |
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 Normal (the default), Maximized, or Minimized. |
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. |
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. |