StatusBarPanel.Text Właściwość

Definicja

Pobiera lub ustawia tekst panelu paska stanu.

C#
public string Text { get; set; }

Wartość właściwości

Tekst wyświetlany na panelu.

Przykłady

Poniższy przykład kodu tworzy kontrolkę StatusBar w formularzu i dodaje dwa StatusBarPanel obiekty. StatusBarPanelPierwszy , o nazwie panel1, wyświetla tekst stanu dla aplikacji. Drugi StatusBarPanel, o nazwie panel2, wyświetla bieżącą datę i używa ToolTipText właściwości StatusBarPanel klasy do wyświetlenia bieżącej godziny. W przykładzie ShowPanels użyto właściwości , aby upewnić się, że panele są wyświetlane zamiast panelu standardowego i używa Panels właściwości w celu uzyskania dostępu do Add metody StatusBar.StatusBarPanelCollection w celu dodania paneli do obiektu StatusBar. W przykładzie użyto AutoSizerównież właściwości , BorderStyle, ToolTipTexti Text w celu zainicjowania StatusBarPanel obiektów. W tym przykładzie przyjęto założenie, że metoda zdefiniowana w przykładzie jest zdefiniowana i wywoływana z konstruktora Formklasy .

C#
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);
}

Uwagi

Ta właściwość reprezentuje tekst wyświetlany, gdy właściwość jest ustawiona Style na Textwartość . Tej właściwości można użyć do wyświetlania informacji o aplikacji w kontrolce StatusBar . Można na przykład użyć Text właściwości , aby wyświetlić informacje pomocy, gdy użytkownik przesuwa wskaźnik myszy nad menu lub wyświetla nazwę i lokalizację pliku otwartego w aplikacji. Aby wyrównać tekst w obiekcie StatusBarPanel, użyj Alignment właściwości .

Dotyczy

Produkt Wersje
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 10

Zobacz też