Home

Status Bars

 

Fundamentals of Status Bars

 

Introduction

A status bar is a horizontal bar that displays in the bottom section of a form or application. The original purpose of the status bar was to display messages to the user. Modern status bars have seen their roles expanded. Still, the primary job a status bar is to show some text depending on what is going on in the application. Here is an example of a status bar that shows the coordinate location of a mouse inside a drawing board of a paint program:

Status Bar

A status bar is a control container that is usually made of sections. The sections of a status bar are called panels. The roles of the panels are left to the programmer.

Creating a Status Bar

 To support status bars, the .NET Framework provides a class named StatusStrip. The StatusStrip class is derived from the ToolStrip class, from which it gets its primary functionality:

type StatusStrip =  
    class 
        inherit ToolStrip 
    end
Author Note

The previous versions of the .NET Framework, namely 1.0, included a class named StatusBar used to create a status bar. That class is still available and you can use it if you want. In our lessons, unless specified otherwise, we will use the StatusStrip class for the status bar.

To create a status bar, declare a variable of type StatusStrip and add it to the Controls collection of the form. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

let exercise = new Form()

let toolbar = new ToolStrip()

let  statusbar = new StatusStrip()
exercise.Controls.Add statusbar |> ignore

do Application.Run exercise

This would produce:

Toolbar

If you have a good reason to do so, you can add more than one status bar to a form.

Characteristics of a Status Bar

 

Introduction

A status bar can be used for its aesthetic characteristics as it can be made to display sunken or raised bars to the bottom of a form:

Status Bar

Other than that, a status bar can be made to display other items.

Like a toolbar, a status bar is an intermediary container, meaning it must be positioned on another container, which is usually a form. The default Dock value of a status bar is Bottom.

   
 

The Items on a Status Bar

To manage its panels, the StatusStrip class inherits the functionalities of its panels from the inherited Items property. To add a label to a status bar, declare a variable of type ToolStripStatusLabel, initialize it, and add it to the Items property of the StatusStrip variable. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

let exercise = new Form()

let toolbar = new ToolStrip()

let  statusbar = new StatusStrip()

let lblMessage = new ToolStripStatusLabel()
statusbar.Items.Add lblMessage |> ignore

exercise.Controls.Add statusbar |> ignore

do Application.Run exercise

Like the label of a toolbar, the label of a status bar can be made to display text, an icon, or both. This is handled by the DisplayStyle property that has the same options as the other.

The label of a status bar is highly configurable. It has the ability to sink or raise its borders. If you want to control the borders of a label, first use its BorderSides property:

member BorderStyle : Border3DStyle with get, set

Here is an example of using it:

open System
open System.Drawing
open System.Windows.Forms

let exercise = new Form()

let toolbar = new ToolStrip()

let  statusbar = new StatusStrip()

let lblMessage = new ToolStripStatusLabel()
lblMessage.BorderSides <- ToolStripStatusLabelBorderSides.All
statusbar.Items.Add lblMessage |> ignore

exercise.Controls.Add statusbar |> ignore

do Application.Run exercise

After setting the BorderSides  property, select the type of border you want in the BorderStyle property. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

let exercise = new Form()

let toolbar = new ToolStrip()

let  statusbar = new StatusStrip()

let lblMessage = new ToolStripStatusLabel()
lblMessage.AutoSize <- false
lblMessage.Width <- 125

lblMessage.BorderSides <- ToolStripStatusLabelBorderSides.All
lblMessage.BorderStyle <- Border3DStyle.Sunken

statusbar.Items.Add lblMessage |> ignore

exercise.Controls.Add statusbar |> ignore

do Application.Run exercise

This would produce:

Border Sides

Besides the label, a status bar can also contain a drop down button, a split button, and/or a progress bar.

   
 

Home Copyright © 2014-2015, FunctionX, Inc. Home