![]() |
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 |
|
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;
}
};
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:
On the right side of the caption, there are three
small buttons called the system buttons, made of the Minimize ( ![]() 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 ( The Maximize
(
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:
|
|
|
||
| Previous | Copyright © 2007 FunctionX, Inc. | Next |
|
|
||