Freigeben über


StatusBar-Klasse

Stellt ein Statusleisten-Steuerelement von Windows dar. Das ToolStripStatusLabel ersetzt Funktionen von früheren Versionen des StatusBar-Steuerelements und erweitert dies um neue Funktionen. Sie können die StatusBar jedoch aus Gründen der Abwärtskompatibilität und zur künftigen Verwendung beibehalten.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class StatusBar
    Inherits Control
'Usage
Dim instance As StatusBar
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class StatusBar : Control
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class StatusBar : public Control
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class StatusBar extends Control
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class StatusBar extends Control

Hinweise

Normalerweise besteht ein StatusBar-Steuerelement aus StatusBarPanel-Objekten, von denen jedes Text und/oder ein Symbol anzeigt. Sie können auch ownerdrawn Bereiche bereitstellen, z. B. eine Statusanzeige oder eine Reihe von Bildern, die den Zustand der Anwendung anzeigen. Ein StatusBar-Steuerelement zeigt i. d. R. Informationen über ein im Form angezeigtes Objekt, die Komponenten des Objekts oder Kontextinformationen an, die sich auf die Operation des Objekts innerhalb der Anwendung beziehen.

Das StatusBar-Steuerelement stellt Eigenschaften bereit, über die die Darstellung des Steuerelements angepasst werden kann. Wenn die StatusBar in einen Formular mit veränderlicher Größe angezeigt wird, können Sie die SizingGrip-Eigenschaft verwenden, um einen Größenziehpunkt in der unteren rechten Ecke des Formulars anzuzeigen. Damit werden Benutzer darauf hingewiesen, dass die Größe des Formulars geändert werden kann. Mit der ShowPanels-Eigenschaft können Sie Bereiche innerhalb der StatusBar oder nur den Wert der Text-Eigenschaft des Steuerelements anzeigen.

Die StatusBar besitzt standardmäßig keine Bereiche. Um der StatusBar Bereiche hinzuzufügen, können Sie die Add-Methode der StatusBar.StatusBarPanelCollection-Klasse verwenden, auf die über die Panels-Eigenschaft des Steuerelements zugegriffen werden kann. Darüber hinaus können Sie das durch die Panels-Eigenschaft bereitgestellte StatusBar.StatusBarPanelCollection-Objekt zum Entfernen von Bereichen aus dem Steuerelement verwenden oder zum Anpassen des Bereichs auf ein bestimmtes StatusBarPanel zugreifen.

Wenn Sie ermitteln möchten, wann auf ein StatusBarPanel-Objekt innerhalb eines StatusBar-Steuerelements geklickt wird, können Sie einen Ereignishandler für das PanelClick-Ereignis erstellen. Zum Ausführen von Ownerdrawn-Vorgängen in einem Bereich können Sie einen Ereignishandler für das DrawItem-Ereignis erstellen. Die an den Ereignishandler übergebenen Ereignisdaten stellen Informationen über den zu zeichnenden Bereich und ein Graphics-Objekt zum Ausführen von Zeichenaufgaben bereit.

Wenn Sie eine Instanz der StatusBar erstellen, werden die Lese-/Schreibeigenschaften auf die Anfangswerte festgelegt. Eine Liste dieser Werte finden Sie unter StatusBar-Konstruktor.

Beispiel

Im folgenden Codebeispiel werden ein StatusBar-Steuerelement in einem Formular erstellt und zwei StatusBarPanel-Objekte hinzugefügt. Eines der StatusBarPanel-Objekte mit dem Namen panel1 zeigt den Statustext für eine Anwendung an. Das zweite StatusBarPanel (panel2) zeigt das aktuelle Datum und mithilfe der ToolTipText-Eigenschaft der StatusBarPanel-Klasse die aktuelle Uhrzeit an. Im Beispiel wird mithilfe der ShowPanels-Eigenschaft sichergestellt, dass die Bereiche anstelle eines Standardbereichs angezeigt werden, und es wird mithilfe der Panels-Eigenschaft auf die Add-Methode der StatusBar.StatusBarPanelCollection zugegriffen, um der StatusBar Bereiche hinzuzufügen. Außerdem werden in dem Beispiel die Eigenschaften AutoSize, BorderStyle, ToolTipText und Text zum Initialisieren der StatusBarPanel-Objekte verwendet. Für dieses Beispiel ist es erforderlich, dass die im Beispiel verwendete Methode im Konstruktor eines Form definiert und aufgerufen wird.

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 time the application was started.
   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.            
   statusBar1.Panels.Add(panel1)
   statusBar1.Panels.Add(panel2)

   ' Add the StatusBar to the form.
   Me.Controls.Add(statusBar1)
End Sub
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 
          //started.
    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.            
    statusBar1.Panels.Add(panel1);
    statusBar1.Panels.Add(panel2);

    // Add the StatusBar to the form.
    this.Controls.Add(statusBar1);
}
private:
   void CreateMyStatusBar()
   {
      // Create a StatusBar control.
      StatusBar^ statusBar1 = gcnew StatusBar;

      // Create two StatusBarPanel objects to display in the StatusBar.
      StatusBarPanel^ panel1 = gcnew StatusBarPanel;
      StatusBarPanel^ panel2 = gcnew 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 time the application
      // was started.
      panel2->ToolTipText = System::DateTime::Now.ToShortTimeString();

      // Set the text of the panel to the current date.
      panel2->Text = "Started: " + 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 );
   }
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.set_BorderStyle(StatusBarPanelBorderStyle.Sunken);

    // Initialize the text of the panel.
    panel1.set_Text("Ready...");

    // Set the AutoSize property to use all remaining space on the StatusBar.
    panel1.set_AutoSize(StatusBarPanelAutoSize.Spring);

    // Display the second panel with a raised border style.
    panel2.set_BorderStyle(StatusBarPanelBorderStyle.Raised);

    // Create ToolTip text that displays the time the application was started.
    panel2.set_ToolTipText("Started: " + System.DateTime.get_Now().ToShortTimeString());
    
// Set the text of the panel to the current date.
    panel2.set_Text(System.DateTime.get_Today().ToLongDateString());
    
// Set the AutoSize property to size the panel to the size of the 
    // contents.
    panel2.set_AutoSize(StatusBarPanelAutoSize.Contents);
    // Display panels in the StatusBar control.
    statusBar1.set_ShowPanels(true);
    // Add both panels to the StatusBarPanelCollection of the StatusBar.    
    statusBar1.get_Panels().Add(panel1);
    statusBar1.get_Panels().Add(panel2);
    // Add the StatusBar to the form.
    this.get_Controls().Add(statusBar1);
} //CreateMyStatusBar

Vererbungshierarchie

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

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

StatusBar-Member
System.Windows.Forms-Namespace
StatusBarPanel
Graphics
ToolStripStatusLabel