![]() |
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 new operator. After initializing the icon, assign it to the form's Icon property. Here is an example: Imports System.Drawing
Imports System.Windows.Forms
Module Exercise
Public Class Starter
Inherits Form
Dim components As System.ComponentModel.Container
Public Sub New()
InitializeComponent()
End Sub
Public Sub InitializeComponent()
Dim CustomIcon As Icon = New Icon("C:\Programs\RedBook.ico")
Icon = CustomIcon
End Sub
End Class
Function Main() As Integer
Dim frmStart As Starter = New Starter
Application.Run(frmStart)
Return 0
End Function
End Module
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.
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 Sub InitializeComponent()
Icon = New Icon("C:\Programs\RedBook.ico")
Text = "Windows Fundmentals - Programming"
End Sub
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 Sub InitializeComponent()
Icon = New Icon("C:\Programs\RedBook.ico")
Text = "Windows Fundmentals - Programming"
ControlBox = True
MinimizeBox = True
MaximizeBox = False
End Sub
This would produce:
|
|
|
||
| Previous | Copyright © 2008 FunctionX, Inc. | Next |
|
|
||