The Forms of an Application:
The Title Bar
The System Icon
A form is made of various sections that allow its control as
a Windows object and other aspects that play a valuable part as a host of other
objects. The top section of a form is made of a long portion called the title
bar.
On the left side of the title bar, the form displays a small
picture called an icon or the system icon. Microsoft Visual Studio 2005 provides a
default icon for all forms. If you want to use a different icon, while the form
is selected, in the Properties window, you can click the Icon field and then
click its ellipsis button .
This would launch the Open dialog box from where you can locate an icon and open
it.
To change the icon programmatically, declare a variable of
type Icon of the System.Drawing namespace and initialize it with
the name of an icon file using the new operator. After initializing the icon,
assign it to the form's Icon property. Here is an example:
private void InitializeComponent()
{
System.Drawing.Icon customIcon =
new System.Drawing.Icon(@"C:\Programs\RedBook.ico");
Icon = customIcon;
}
Whether you had assigned an icon to the for or not, you can
control whether the form should display an icon. To support this, the Form class
is equipped with a Boolean property named ShowIcon. If you set this
property to false, the icon would not appear in the title bar of the form. If
the Form.ShowIcon property is set to true, which is its default value,
the form's title bar would display an icon.
Practical
Learning: Configuring a Form's Title Bar
The Form's Caption
On the right side of the system icon, there is a word or a
group of words called the caption. By default, the caption displays the name of
the form. If you want to change the caption, while the form is selected, in the
Properties window, click the Text field and type anything you want. After typing
the text, press Enter to display it on the form.
At design time, the caption is
made of text that you type "as is". At run time, you can change the
caption to display a more complex text that could be a changing time, the result
of a calculation, etc. Here is an example:
private void InitializeComponent()
{
Icon = new System.Drawing.Icon(@"C:\Programs\RedBook.ico");
Text = "Windows Fundmentals - Programming";
}
This would produce:
Practical
Learning: Setting a Form's Caption
The System Buttons
On the right side of the caption, there are three
small buttons called the system buttons, made of the Minimize (,,
or ), the Maximize
(,,
or ), and the
, or )
buttons.
The presence or absence of these buttons is controlled by the Boolean ControlBox
property whose default value is True to indicate that the form will be
equipped with the system buttons. If you set it to False, no system button
would be displayed:
In this case, the user would not be able to close the
form using the system buttons. Therefore, if you create this type of form, make sure you provide the user with a way to close
it.
The Minimize (,,
or ) button is controlled by a Boolean property called MinimizeBox. By
default, when you freshly create a form, this property is set to True and
the form would display a Minimize button.
The Maximize
(,,
or ) button is controlled by the Boolean MaximizeBox
property, which also is set to True by default. Depending on what you are
trying to achieve in your application, you can change the value of either
one or both of these properties. The four combinations are as follows:
To change a system button programmatically, call the
desired button's property and assign it a true or false value. Here is an
example that makes sure the user cannot maximize the form:
private void InitializeComponent()
{
Icon = new System.Drawing.Icon(@"C:\Programs\RedBook.ico");
Text = "Windows Fundmentals - Programming";
ControlBox = true;
MinimizeBox = true;
MaximizeBox = false;
}
Practical
Learning: Configuring a Form's System Buttons