Search | Contact | Link To Us  

      VB .NET       

.NET Defined
OOP with VB
VB Language
Win Forms
Windows Controls
ADO .NET
User Controls
File Handling
Multithreading
Deployment
XML Web Services Essential XML
Resources
Discussions
ASP.NET
About



Advertisement


     HomeWindows Controls> StatusBar 

StatusBar 

Status Bars are used to display status messages at the bottom of the form. They are generally used to provide additional information, such as page numbers, display a message, etc. There are two kinds of status bars: simple status bars and status bars that display a panel. Simple status bars display a single message on the status bar and a status bar with panels can display multiple messages. Below is the image of a StatusBar control.

StatusBar Control

Notable properties of the Status bar:

Panels: Gets the collection of status bar panels in a status bar.
ShowPanels: Default is True. You can set it to False if you don't want to show panels.
Text: Gets/Sets the text to be displayed.

StatusBar Event

Defalut event of the StatusBar control is the PanelClick event which looks like this in Code:

Private Sub StatusBar1_PanelClick(ByVal sender As System.Object, ByVal e _
As System.Windows.Forms.StatusBarPanelClickEventArgs) Handles StatusBar1.PanelClick

End Sub

Sample code for a Simple Status Bar

From the toolbox add a status bar control to the form. The following code will display the message "Hello" on the StatusBar when the form loads.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
StatusBar1.Text = "Hello"
End Sub

Status Bars with Panels

You can add panels to a status bar by opening it's properties window and clicking the Panels property. When you click the Panels property it opens the StatusBarPanel Collection Editor which looks like the image below.

StausBarPanel Collection Editor


You add panels by clicking the Add button found in the editor. While adding panels you can set the Text to be displayed for each panel, an icon, tooltip, width for each panel you add.

To add panels to status bar in code we use the StatusBar.Panel.Add method and StatusBar.Panels.Remove, StatusBar.Panels.RemoveAt to remove the panels. To access text in each panel you use the text property of StatusbarPanel as: StatusBarPanels(0).Text="I am panel one".

To handle status bar panel clicks you use the PanelClick event as shown in the code below. To work with this code, add a status bar control to the form, open it's properties window, select the Panels property and add three status bar panels. For StatusBarPanel1 set the text "More VB .NET?  Please Visit ->", for StatusBarPanel2 set the text "MSDN" and for StatusBarPanel3 "Startvbdotnet.com". The form in design view should look like the image below.

Switch to code view and paste the following code:

Private Sub StatusBar1_PanelClick(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.StatusBarPanelClickEventArgs) Handles StatusBar1.PanelClick
If e.StatusBarPanel Is StatusBar1.Panels(1) Then
'checks if status bar panel2 is clicked and if true opens a webpage
System.Diagnostics.Process.Start("www.msdn.mcirosoft.com")
ElseIf e.StatusBarPanel Is StatusBar1.Panels(2) Then
'checks if status bar panel3 is clicked and if true opens a webpage
System.Diagnostics.Process.Start("www.startvbdotnet.com")
End If
End Sub

When you run the application and click on MSDN you will be taken to MSDN and Startvbdotnet.com if you click on Startvbdotnet.

For Properties See: Control Object Properties - Form Properties

  Privacy Policy | Terms of Use | Site Map | Contact

  © 2004-2007 Startvbdotnet.com. All rights reserved.