Spotlight on the StatusBar Control

July 5th, 2012 by David Corrales
Last updated on July 5th, 2012


The “Spotlight on Controls” series focuses on a single WinForms control in PowerShell Studio 2012, details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms.

Last time we took a look at the NotifyIcon control. This time we will look at the StatusBar control:


Represents a Windows status bar control.

StatusBar Icon

Default Event: PanelClick

Why use a StatusBar control?

Use the StatusBar control, to display status information to the user. The StatusBar can also be used for user interaction but typically plays a informative roll.


Important Properties:


The collection of StatusBar panels contained within the control. Panels represent a subsection of the StatusBar that can display text and/or an icon.

Adding Panels:

You can add panels by using the Property Pane:

Panels in Property Pane

Next you will be presented with a dialog that allows you to add or remove panels:

StatusBarPanel Collection Editor

Once you add a Panel, it will appear in the control list of the Property Pane thus allowing you to alter the properties directly without having to access the collection editor.

Edit StatusBarPane in Property Pane

Each panel consists of a StatusBarPanel object:

StatusBarPanel [System.Windows.Forms.StatusBarPanel]

Properties Description
Alignment The alignment of text and icons within the status bar panel.
Values (Default: Left):
Left Alignment
Right Alignment
Center Alignment
AutoSize Indicates whether the status bar panel is automatically resized.
Values (Default: None):

The StatusBarPanel does not change size when the StatusBar control resizes.


The StatusBarPanel shares the available space on the StatusBar (the space not taken up by other panels whose AutoSize property is set to None or Contents) with other panels that have their AutoSize property set to Spring.

The width of the StatusBarPanel is determined by its contents.

BorderSize The border style of the status bar panel. The difference between Raised and Sunken can only be seen on older versions of Windows.
Values (Default: Sunken):

No border is displayed.

The StatusBarPanel is displayed with a three-dimensional raised border.

The StatusBarPanel is displayed with a three-dimensional sunken border.

Icon The icon to display within the status bar panel.
Icon Panel
MinWidth The minimum allowed width of the status bar panel within the StatusBar control.
Text The text of the status bar panel.
ToolTipText ToolTip text associated with the status bar panel.
Panel ToolTip
Width The width of the status bar panel within the StatusBar control.


Adding Panels via Script Editor:

You can manually add panels using the Panel properties’ Add methods:

[StatusBarPanel] Add ([string] text)

Adds a StatusBarPanel with the specified text to the collection.

$panel = $statusbar1.Panels.Add("New Panel")


[int] Add ([StatusBarPanel] value)

Adds a StatusBarPanel to the collection and returns an index.

$panel = New-Object System.Windows.Forms.StatusBarPanel
$index = $statusbar1.Panels.Add($panel)



This property indicates whether any panels that have been added to the control are displayed.

ShowPanels set to True:


ShowPanels set to False:
ShowPanels Set to False



This property indicates whether a sizing grip is displayed in the lower-right corner of the control. This property is mainly cosmetic and should be set to False when using a fixed sized Form. Such as  when the form’s FormBorderStyle property is set to FixedDialog. For more details about the Form control and the FormBorderStyle property, please refer to the Spotlight on the Form Control article.



This property indicates the text associated with the StatusBar control. Use this property to display a message in the StatusBar.
Note: This text is not displayed when the ShowPanels property is set to True.

$statusbar1.Text = "Loading..."


Important Events:


This event occurs when a StatusBarPanel object on a StatusBar control is clicked.
The PanelClick event uses the following argument, which is accessible via the $_ variable:


Properties Description
Button Gets which mouse button was pressed.
Clicks Gets the number of times the mouse button was pressed and released.
Location Gets the location of the mouse during the generating mouse event.

Gets the StatusBarPanel that was clicked.

X Gets the x-coordinate of the mouse during the generating mouse event.
Y Gets the y-coordinate of the mouse during the generating mouse event.


How to Display Different Context Menus for Each Panel:

The StatusBar has a ContextMenuStrip property that displays a context menu when the user right clicks on the Statusbar. But what if you want to display a different menu depending on which panel is clicked? To do this you have clear the StatusBar’s ContextMenuStrip property and handle the StatusBar’s PanelClick event as follows:

#Event Argument: $_ = [System.Windows.Forms.StatusBarPanelClickEventArgs]
    if($_.Button -eq 'Right')
        if($_.StatusBarPanel -eq $statusbarpanel2)
            $contextmenustrip2.Show($statusbar1, $_.Location)
        elseif($_.StatusBarPanel -eq $statusbarpanel1)
            $contextmenustrip1.Show($statusbar1, $_.Location)

First it checks if the user Right clicked on a panel and then determines which panel was clicked. Depending on which panel was clicked you display the corresponding context menu.

Panel ContextMenu 1

Panel ContextMenu 2

For more details on the ContextMenuStrip please refer to the Spotlight on the ContextMenuStrip article.


You can download the StatusBar Sample from our Downloads section.


[Google+]   [Facebook]   [LinkedIn]   [StumbleUpon]   [Digg]   [Reddit]   [Google Bookmark]  

Tags: , , , ,

Comments are closed.