This documentation is archived and is not being maintained.

StatusBar Class

Represents a Windows status bar control. Although ToolStripStatusLabel replaces and adds functionality to the StatusBar control of previous versions, StatusBar is retained for both backward compatibility and future use if you choose.

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

public class StatusBar : Control

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 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.

The following code 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, 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 requires that the method defined in the example is defined and called from the constructor of a Form.

		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 time the application was  
			panel2.ToolTipText = "Started: " + 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.			

			// Add the StatusBar to the form. 

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0