You are on page 1of 6

BCA 204A31: Visual Programming

UNIT II - Lecture 1
Introduction to the windows forms
What is a Window Form?
• Visual Basic Form is the container for all the controls that make up the user interface
• Every window in a running visual basic application is a form, thus the terms form and
window describe the same entity
• Visual Studio creates a default form to create a Windows Forms Application.

Creating a Window Forms Application by the following steps in Microsoft Visual Studio
- File → New Project → Windows Forms Applications

Finally, select OK, Microsoft Visual Studio creates a project and displays following window
Form with a name Form1.

Every form will have title bar on which the form's caption is displayed and there will be
buttons to close, maximize and minimize the form shown below −
click the icon on the top left corner, it opens the control menu, which contains the various
commands to control the form like to move control from one place to another place, to
maximize or minimize the form or to close the form.
Setting the Title Bar Text:
Every form will have title bar on which the form's caption is displayed and there will be
buttons to close, maximize and minimize.
Title Bar Height:
Height of the title bar can be changed by using the Style.TitleBar.Height property.
Me.Style.TitleBar.Height = 45
Text Alignment:
Text on the title bar can be aligned horizontally and vertically by using
the Style.TitleBar.TextHorizontalAlignment and Style.TitleBar.TextVerticalAlignment
properties respectively.

Me.Style.TitleBar.TextHorizontalAlignment = HorizontalAlignment.Center

Me.Style.TitleBar.TextVerticalAlignment = VerticalAlignment.Top

Customization of title bar buttons:


Icons on the title bar buttons can be changed by loading any custom icon by using the button
image properties in the Style.TitleBar such
as CloseButtonImage, MaximizeButtonImage and MinimizeButtonImage.
By default, the title bar buttons have the following states:

• Normal state
• Hover state
• Pressed state
Icons for the title bar buttons can be changed to normal, hovered, and pressed states by using
the image properties of the corresponding state such
as CloseButtonHoverImage and MaximizeButtonPressedImage.

Hiding the title bar buttons:

Buttons in the title bar can be hide by disabling


the MinimizeBox, MaximizeBox and CloseButtonVisible properties.
Me.MinimizeBox = False

Me.MaximizeBox = False

Rich text formatting:


Rich text can be displayed inside the title bar by enabling
the Style.TitleBar.AllowRichText property and adding the proper rich text to
the Text property of the form.

'Enabling the rich text support

Me.Style.TitleBar.AllowRichText = True

'Adding rich text Me.Text = "{\\rtf1\\ansi\\deff0{\\colortbl;\\red150\\green0\\blue20;\\red100\


\green0\\blue150;}" + "{\\fonttbl{\\f0 Segoe UI;\r\n}}\\qc\\f0\\fs23 {\\cf1 Untitled* \\cf2 - \\b
Custom Text Editor}}"
NOTE

Adding rich text to the Text property will have no effect, if the AllowRichText property
is false.

Loading user control to the title bar:

The SfForm allows you to load any user control into the title bar instead of title bar text by
using the TitleBarTextControl property. Size of the user control should be set properly to fit
the control within the title bar.

Icon backcolor:

Can customize the back color of the icon in title bar using the IconBackColor property.

'Sets the icon back color of the title bar.

Me.Style.TitleBar.IconBackColor = Color.Olive
Caption image:

Can change the caption image in title bar by using the CaptionImage property.

'Sets the caption image of the title bar.

Me.Style.TitleBar.CaptionImage = SystemIcons.Error.ToBitmap()

You might also like