How to: Add Panels to a StatusBar Control

System_CAPS_ICON_important.jpg Important

The StatusStrip and ToolStripStatusLabel controls replace and add functionality to the StatusBar and StatusBarPanel controls; however, the StatusBar and StatusBarPanel controls are retained for both backward compatibility and future use, if you choose.

The programmable area within a StatusBar Control control consists of instances of the StatusBarPanel class. These are added through additions to the StatusBar.StatusBarPanelCollection class.

To add panels to a status bar

  1. In a procedure, create status-bar panels by adding them to the StatusBar.StatusBarPanelCollection. Specify property settings for individual panels by using its index passed through the Panels property.

    In the following code example, the path set for the location of the icon is the My Documents folder. This location is used because you can assume that most computers running the Windows operating system will include this folder. Choosing this location also allows users with minimal system access levels to safely run the application. The following example requires a form with a StatusBar control already added.

    System_CAPS_ICON_note.jpg Note

    The StatusBar.StatusBarPanelCollection is a zero-based collection, so code should proceed accordingly.

    public void CreateStatusBarPanels()  
       // Create panels and set text property.  
       // Set properties of StatusBar panels.  
       // Set AutoSize property of panels.  
       statusBar1.Panels[0].AutoSize = StatusBarPanelAutoSize.Spring;  
       statusBar1.Panels[1].AutoSize = StatusBarPanelAutoSize.Contents;  
       statusBar1.Panels[2].AutoSize = StatusBarPanelAutoSize.Contents;  
       // Set BorderStyle property of panels.  
       statusBar1.Panels[0].BorderStyle =  
       statusBar1.Panels[1].BorderStyle = StatusBarPanelBorderStyle.Sunken;  
       statusBar1.Panels[2].BorderStyle = StatusBarPanelBorderStyle.Raised;  
       // Set Icon property of third panel. You should replace the bolded  
       // icon in the sample below with an icon of your own choosing.  
       // Note the escape character used (@) when specifying the path.  
       statusBar1.Panels[2].Icon =   
          new System.Drawing.Icon (System.Environment.GetFolderPath _  
       (System.Environment.SpecialFolder.Personal) _  
       + @"\Icon.ico");  
       statusBar1.ShowPanels = true;  

Collection Editor Dialog Box
How to: Set the Size of Status-Bar Panels
Walkthrough: Updating Status Bar Information at Run Time
How to: Determine Which Panel in the Windows Forms StatusBar Control Was Clicked
StatusBar Control Overview