Export (0) Print
Expand All
2 out of 4 rated this helpful - Rate this topic

StatusBar Class

Represents a Windows status bar control.

For a list of all members of this type, see StatusBar Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.StatusBar

[Visual Basic]
Public Class StatusBar
   Inherits Control
[C#]
public class StatusBar : Control
[C++]
public __gc class StatusBar : public Control
[JScript]
public class StatusBar extends Control

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Typically a StatusBar control consists of StatusBarPanel objects, each of which displays text and/or an icon. You can also provide owner-drawn panels to provide custom panels such as a progress bar or a series of images that displays the state of your application. A StatusBar control typically displays information about an object being viewed on a Form, the object's components, or contextual information that relates to that object's operation within your application.

The StatusBar control provides properties that enable you to customize the appearance of the control. If the StatusBar is displayed on a form that can be resized, you can use the SizingGrip property to display a sizing grip in the lower-right corner of the form to indicate to users that the form can be resized. The ShowPanels property enables you to display panels within your StatusBar or to display only the value of the Text property of the control.

The default StatusBar has no panels. To add panels to a StatusBar you can use the Add method of the StatusBar.StatusBarPanelCollection class that is accessible through the Panels property of the control. You can also use the StatusBar.StatusBarPanelCollection object provided through the Panels property to remove panels from the control and access a specific StatusBarPanel object to manipulate the panel.

If you want to determine when a StatusBarPanel object within a StatusBar control is clicked, you can create an event handler for the PanelClick event. To perform owner-draw operations on a panel, you can create an event handler for the DrawItem event. The event data passed to the event handler provides information on the panel to draw and a Graphics object to use to perform drawing tasks.

When you create an instance of StatusBar, the read/write properties are set to initial values. For a list of these values, see the StatusBar constructor.

Example

[Visual Basic, C#, C++] The following example creates a StatusBar control on a form and adds two StatusBarPanel objects. One of the StatusBarPanel objects, named panel1, displays status text for an application. The second StatusBarPanel object, named panel2, displays the current date and uses the ToolTipText property of the StatusBarPanel class to display the current time. The example uses the ShowPanels property to ensure that the panels are displayed instead of a standard panel, and it uses and the Panels property to access the Add method of the StatusBar.StatusBarPanelCollection to add the panels to the StatusBar. The example also uses the AutoSize, BorderStyle, ToolTipText, and Text properties to initialize the StatusBarPanel objects. This example assumes that the method defined in the example is defined and called from the constructor of a Form.

[Visual Basic] 
Private Sub CreateMyStatusBar()
   ' Create a StatusBar control.
   Dim statusBar1 As New StatusBar()
   ' Create two StatusBarPanel objects to display in the StatusBar.
   Dim panel1 As New StatusBarPanel()
   Dim panel2 As New StatusBarPanel()

   ' Display the first panel with a sunken border style.
   panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken
   ' Initialize the text of the panel.
   panel1.Text = "Ready..."
   ' Set the AutoSize property to use all remaining space on the StatusBar.
   panel1.AutoSize = StatusBarPanelAutoSize.Spring
   ' Display the second panel with a raised border style.
   panel2.BorderStyle = StatusBarPanelBorderStyle.Raised
   ' Create ToolTip text that displays the current time.
   panel2.ToolTipText = System.DateTime.Now.ToShortTimeString()
   ' Set the text of the panel to the current date.
   panel2.Text = System.DateTime.Today.ToLongDateString()
   ' Set the AutoSize property to size the panel to the size of the contents.
   panel2.AutoSize = StatusBarPanelAutoSize.Contents

   ' Display panels in the StatusBar control.
   statusBar1.ShowPanels = True

   ' Add both panels to the StatusBarPanelCollection of the StatusBar.            
   statusBar1.Panels.Add(panel1)
   statusBar1.Panels.Add(panel2)

   ' Add the StatusBar to the form.
   Me.Controls.Add(statusBar1)
End Sub

[C#] 
private void CreateMyStatusBar()
{
    // Create a StatusBar control.
    StatusBar statusBar1 = new StatusBar();
    // Create two StatusBarPanel objects to display in the StatusBar.
    StatusBarPanel panel1 = new StatusBarPanel();
    StatusBarPanel panel2 = new StatusBarPanel();

    // Display the first panel with a sunken border style.
    panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken;
    // Initialize the text of the panel.
    panel1.Text = "Ready...";
    // Set the AutoSize property to use all remaining space on the StatusBar.
    panel1.AutoSize = StatusBarPanelAutoSize.Spring;
    // Display the second panel with a raised border style.
    panel2.BorderStyle = StatusBarPanelBorderStyle.Raised;
    // Create ToolTip text that displays the current time.
    panel2.ToolTipText = System.DateTime.Now.ToShortTimeString();
    // Set the text of the panel to the current date.
    panel2.Text = System.DateTime.Today.ToLongDateString();
    // Set the AutoSize property to size the panel to the size of the contents.
    panel2.AutoSize = StatusBarPanelAutoSize.Contents;
                
    // Display panels in the StatusBar control.
    statusBar1.ShowPanels = true;

    // Add both panels to the StatusBarPanelCollection of the StatusBar.            
    statusBar1.Panels.Add(panel1);
    statusBar1.Panels.Add(panel2);

    // Add the StatusBar to the form.
    this.Controls.Add(statusBar1);
}

[C++] 
private:
    void CreateMyStatusBar()
    {
        // Create a StatusBar control.
        StatusBar* statusBar1 = new StatusBar();
        // Create two StatusBarPanel objects to display in the StatusBar.
        StatusBarPanel* panel1 = new StatusBarPanel();
        StatusBarPanel* panel2 = new StatusBarPanel();

        // Display the first panel with a sunken border style.
        panel1->BorderStyle = StatusBarPanelBorderStyle::Sunken;
        // Initialize the text of the panel.
        panel1->Text = S"Ready...";
        // Set the AutoSize property to use all remaining space on the StatusBar.
        panel1->AutoSize = StatusBarPanelAutoSize::Spring;
        // Display the second panel with a raised border style.
        panel2->BorderStyle = StatusBarPanelBorderStyle::Raised;
        // Create ToolTip text that displays the current time.
        panel2->ToolTipText = System::DateTime::Now.ToShortTimeString();
        // Set the text of the panel to the current date.
        panel2->Text = System::DateTime::Today.ToLongDateString();
        // Set the AutoSize property to size the panel to the size of the contents.
        panel2->AutoSize = StatusBarPanelAutoSize::Contents;

        // Display panels in the StatusBar control.
        statusBar1->ShowPanels = true;

        // Add both panels to the StatusBarPanelCollection of the StatusBar.            
        statusBar1->Panels->Add(panel1);
        statusBar1->Panels->Add(panel2);

        // Add the StatusBar to the form.
        this->Controls->Add(statusBar1);
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

StatusBar Members | System.Windows.Forms Namespace | StatusBarPanel | Graphics

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.