Home

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 Ellipsis. 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 LearningPractical Learning: Configuring a Form's Title Bar

  1. On the main menu, click Project -> Add New Item...
  2. In the Templates list, click Icon File
  3. Set the Name to cpas click Add
  4. Design the icon as follows:
     
    Icon Design
  5. To continue with the icon design, on the main menu, click Image -> New Image Type...
  6. On the New Icon Image Type, click 16x16, 256 colors line:
     
    New Icon Image Type
  7. Click OK
  8. Design it as follows:
     
    Icon Design
  9. To save the icon, on the Standard toolbar, click the Save All button Save All
  10. Close the window tab that contains the icon designed
  11. Click the body of the form to make sure it is selected. In the Properties window, click Icon and click its ellipsis button Ellipsis
  12. On the Open dialog box, locate the folder in which you had saved the project and select the cpas icon
     
    Open
  13. Click Open
     
    A form with a System icon
  14. Execute the application to test it
  15. Close it and return to your programming environment

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:

The Caption of a Form

Practical LearningPractical Learning: Setting a Form's Caption

  1. While the form is selected, in the Properties window, click Text and type
    College Park Auto Shop - Customer Repair Order
  2. Press Enter

The System Buttons

On the right side of the caption, there are three small buttons called the system buttons, made of the Minimize (Minimize,, or ), the Maximize (Maximize,, or ), and the Close (Close, , 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:

A form without the control box

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 (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 (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:

MaximizeBox MinimizeBox Display Result
True True Maximize = True and Minimize = True The form can be minimized or maximized
True False Maximize = True and Minimize = False The form can be maximized but cannot be minimized
False True Maximize = False and Minimize = True The form can be minimized but cannot be maximized 
False False Maximize = False and Minimize = False The form can be neither minimized nor maximized

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;
}

This would produce:

Control Box

Practical LearningPractical Learning: Configuring a Form's System Buttons

  1. To make sure that the user cannot maximize the form, on the Properties window, click the MaximizeBox field to reveal its combo box and select False
  2. Test the program
     
    College Park Auto Shop - Customer Repair Order
  3. Close the form and return to your programming environment
 

Previous Copyright © 2007 FunctionX, Inc. Next