--- title: "How to: Add Panels to a StatusBar Control" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" helpviewer_keywords: - "panels [Windows Forms], status bars" - "status bars [Windows Forms], adding panels" - "StatusBar control [Windows Forms], adding panels" ms.assetid: 835e3902-288c-4c38-9d69-0696d8695009 --- # How to: Add Panels to a StatusBar Control > [!IMPORTANT] > The and controls replace and add functionality to the and controls; however, the and controls are retained for both backward compatibility and future use, if you choose. The programmable area within a [StatusBar Control](statusbar-control-windows-forms.md) control consists of instances of the class. These are added through additions to the class. ### To add panels to a status bar 1. In a procedure, create status-bar panels by adding them to the . Specify property settings for individual panels by using its index passed through the 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 control already added. > [!NOTE] > The is a zero-based collection, so code should proceed accordingly. ```vb Public Sub CreateStatusBarPanels() ' Create panels and set text property. StatusBar1.Panels.Add("One") StatusBar1.Panels.Add("Two") StatusBar1.Panels.Add("Three") ' 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 = StatusBarPanelBorderStyle.Raised 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. StatusBar1.Panels(2).Icon = New _ System.Drawing.Icon(System.Environment.GetFolderPath _ (System.Environment.SpecialFolder.Personal) _ & "\Icon.ico") StatusBar1.ShowPanels = True End Sub ``` ```csharp public void CreateStatusBarPanels() { // Create panels and set text property. statusBar1.Panels.Add("One"); statusBar1.Panels.Add("Two"); statusBar1.Panels.Add("Three"); // 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 = StatusBarPanelBorderStyle.Raised; 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; } ``` ```cpp public: void CreateStatusBarPanels() { // Create panels and set text property. statusBar1->Panels->Add("One"); statusBar1->Panels->Add("Two"); statusBar1->Panels->Add("Three"); // 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 = StatusBarPanelBorderStyle::Raised; statusBar1->Panels[1]->BorderStyle = StatusBarPanelBorderStyle::Sunken; statusBar1->Panels[2]->BorderStyle = StatusBarPanelBorderStyle::Raised; // Set Icon property of third panel. // You should replace the bolded image // in the sample below with an icon of your own choosing. statusBar1->Panels[2]->Icon = gcnew System::Drawing::Icon(String::Concat( System::Environment::GetFolderPath( System::Environment::SpecialFolder::Personal), "\\Icon.ico")); statusBar1->ShowPanels = true; } ``` ## See also - - - [Collection Editor Dialog Box](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/xc4yyekt(v=vs.100)) - [How to: Set the Size of Status-Bar Panels](how-to-set-the-size-of-status-bar-panels.md) - [Walkthrough: Updating Status Bar Information at Run Time](walkthrough-updating-status-bar-information-at-run-time.md) - [How to: Determine Which Panel in the Windows Forms StatusBar Control Was Clicked](determine-which-panel-wf-statusbar-control-was-clicked.md) - [StatusBar Control Overview](statusbar-control-overview-windows-forms.md)