Home

The Form's 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 gcnew operator. After initializing the icon, assign it to the form's Icon property. Here is an example:

#include <windows.h>

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

public ref class CExercise : public Form
{
public:
    CExercise()
    {
	InitializeComponent();
    }

    void InitializeComponent()
    {
	System::Drawing::Icon ^ customIcon =
			gcnew System::Drawing::Icon(L"C:\\Programs\\RedBook.ico");
        Icon = customIcon;
    }
};

Practical LearningPractical Learning: Configuring a Form's Title Bar

  1. In the Resource View, right-click CPAR1 -> Add -> Resource...
     
    Add Resource
  2. In the Add Resource dialog box, click Icon and click New
  3. Design the icon as follows:
     
    Icon Design
  4. To continue with the icon design, on the main menu, click Image -> New Image Type... On the New Icon Image Type, make sure the first 16x16, 16 colors item is selected:
     
    New Icon Image Type
  5. Click OK
  6. Design it as follows:
     
    Icon Design
  7. In the Resource View, click IDI_ICON1
  8. In the Properties window, change the filename to cpas.ico
  9. Change the ID to IDI_CPAS
  10. To save the icon, on the Standard toolbar, click the Save All button
  11. Close the window tab that contains the icon designed
  12. Click the body of the form to make sure it is selected. In the Properties window, click Icon and click its ellipsis button Ellipsis
  13. On the Open dialog box, locate the folder in which you had saved the project and select the icon1 icon
     
    Open Icon
  14. Click Open
     
    A form with a System icon
  15. Execute the application to test it
  16. 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:

public ref class CExercise : public Form
{
public:
    CExercise()
    {
	InitializeComponent();
    }

    void InitializeComponent()
    {
	Text = L"Windows Fundmentals - Programming";
        Icon = gcnew System::Drawing::Icon(L"C:\\Programs\\RedBook.ico");
    }
};

This would produce:

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 The form can be minimized or maximized
True False The form can be maximized but cannot be minimized
False True The form can be minimized but cannot be maximized 
False 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:

public ref class CExercise : public Form
{
public:
    CExercise()
    {
	InitializeComponent();
    }

    void InitializeComponent()
    {
	Text = L"Windows Fundmentals - Programming";
        Icon = gcnew System::Drawing::Icon(L"C:\\Programs\\RedBook.ico");
	
	ControlBox = true;
	MinimizeBox = true;
	MaximizeBox = false;
    }
};

This would produce:

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
     
  3. Close the form and return to your programming environment
 
 

Previous Copyright © 2007 FunctionX, Inc. Next