Gewusst wie: Hinzufügen von Bereichen zu einem StatusBar-Steuerelement

Aktualisiert: November 2007

Wichtiger Hinweis:

Obwohl die Steuerelemente StatusBar und StatusBarPanel durch die Steuerelemente StatusStrip und ToolStripStatusLabel ersetzt und funktionell erweitert werden, werden die Steuerelemente StatusBar und StatusBarPanel sowohl aus Gründen der Abwärtskompatibilität als auch, falls gewünscht, für die zukünftige Verwendung beibehalten.

Der programmierbare Bereich innerhalb eines StatusBar-Steuerelement (Windows Forms)-Steuerelements besteht aus Instanzen der StatusBarPanel-Klasse. Diese werden der StatusBar.StatusBarPanelCollection-Klasse durch Zusätze hinzugefügt.

So fügen Sie einer Statusleiste Bereiche hinzu

  • Erstellen Sie in einer Prozedur Bereiche einer Statusleiste, indem Sie diese der StatusBar.StatusBarPanelCollection hinzufügen. Geben Sie die Einstellungen für die Eigenschaften der einzelnen Bereiche an, indem Sie den entsprechenden, durch die Panels-Eigenschaft übergebenen Index verwenden.

    Im folgenden Codebeispiel wurde als Speicherort für das Symbol der Ordner Eigene Dateien festgelegt. Dieser Speicherort wird verwendet, weil vorausgesetzt werden kann, dass die meisten Computer mit Windows als Betriebssystem über einen Ordner mit diesem Namen verfügen. Dieser Speicherort ermöglicht auch Benutzern mit minimalen Systemzugriffsberechtigungen, die Anwendung sicher auszuführen. Im folgenden Beispiel wird davon ausgegangen, dass einem Formular bereits ein StatusBar-Steuerelement hinzugefügt wurde.

    Hinweis:

    Die StatusBar.StatusBarPanelCollection ist eine nullbasierte Auflistung, sodass der Code entsprechend fortgesetzt werden sollte.

    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
    
    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;
    }
    
    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;
       }
    

Siehe auch

Aufgaben

Gewusst wie: Festlegen der Größe eines Statusleistenbereichs

Exemplarische Vorgehensweise: Aktualisieren von Statusleisteninformationen zur Laufzeit

Gewusst wie: Bestimmen, auf welchen Bereich im StatusBar-Steuerelement in Windows Forms geklickt wurde

Referenz

Dialogfeld "Auflistungs-Editor"

Übersicht über das StatusBar-Steuerelement (Windows Forms)

StatusBar

ToolStripStatusLabel