StatusBarPanel 類別

定義

代表 StatusBar 控制項中的面板。

.NET 5 和更新版本不提供這個類別。 請改用 ToolStripStatusLabel 控制項,以取代和擴充 StatusBarPanel 控制項。

public ref class StatusBarPanel : System::ComponentModel::Component, System::ComponentModel::ISupportInitialize
public class StatusBarPanel : System.ComponentModel.Component, System.ComponentModel.ISupportInitialize
type StatusBarPanel = class
    inherit Component
    interface ISupportInitialize
Public Class StatusBarPanel
Inherits Component
Implements ISupportInitialize
繼承
實作

範例

下列程式碼範例會在表單上建立 控制項,並新增兩 StatusBarPanelStatusBar 物件。 名為 的第一個 StatusBarPanelpanel1 會顯示應用程式的狀態文字。 第二 StatusBarPanel 個名為 panel2 的 會顯示目前的日期,並使用 ToolTipText 類別的 StatusBarPanel 屬性來顯示目前的時間。 此範例會 ShowPanels 使用 屬性來確保顯示面板,而不是標準面板,並使用 Panels 屬性來存取 Add 的 方法 StatusBar.StatusBarPanelCollection ,將面板新增至 StatusBar 。 此範例也會使用 AutoSizeBorderStyleToolTipTextText 屬性來初始化 StatusBarPanel 物件。 這個範例假設範例中定義的 方法是由 的建構函式所定義,並從 的 Form 建構函式呼叫。

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.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 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

備註

.NET 5 和更新版本不提供這個類別。 請改用 ToolStripStatusLabel 控制項。

表示 StatusBarPanel 控制項中的 StatusBar.StatusBarPanelCollectionStatusBar 個別面板。 StatusBarPanel可以包含文字和/或圖示,可用來反映應用程式的狀態。 使用 可 StatusBar.StatusBarPanelCollection 透過 StatusBar.Panels 控制項的 StatusBar 屬性存取的 ,以擷取、新增或移除個別 StatusBarPanel 的 。

提供 StatusBarPanel 屬性,可讓您修改控制項內 StatusBar 面板的顯示行為。 您可以使用 Icon 屬性在面板中顯示圖示。 這個屬性可用來在應用程式中提供狀態的圖形標記法。 屬性 Alignment 可讓您指定文字和/或圖示在面板內對齊的方式。 若要確保您的面板已適當調整大小以符合面板的文字,您可以使用 AutoSize 屬性自動調整面板的大小,以符合面板的文字,或填滿控制項內的 StatusBar 剩餘空間。 屬性 MinWidth 可讓您指定面板的最小寬度,以確保其不會小於所要顯示的資料。

控制項 StatusBar 通常用來顯示應用程式的說明資訊或狀態資訊。 通常,請務必顯示面板中所呈現之資料的其他資訊。 每當滑鼠指標停留在面板上時,您可以使用 ToolTipText 屬性來顯示資訊。

StatusBar雖然控制項通常用來顯示文字資訊,但您也可以提供自己的顯示類型給 StatusBarPanel 。 屬性 Style 可讓您指定 繪製 的方式 StatusBarPanel 。 根據預設,如果屬性) 中指定的 Icon 屬性,則會 Style 使用 屬性來顯示內容 (和圖示的值 Text 。 如果 屬性設定為 OwnerDraw ,您可以將自己的資訊繪製到面板中。 您可以使用此功能在面板中繪製進度列或動畫圖標。

當您建立 類別的 StatusBarPanel 實例時,讀取/寫入屬性會設定為初始值。 如需這些值的清單,請參閱建 StatusBarPanel 構函式。

建構函式

StatusBarPanel()

初始化 StatusBarPanel 類別的新執行個體。

屬性

Alignment

取得或設定狀態列面板內文字與圖示的對齊方式。

AutoSize

取得或設定值,指出狀態列面板是否會自動調整大小。

BorderStyle

取得或設定狀態列面板的框線樣式。

CanRaiseEvents

取得值,指出元件是否能引發事件。

(繼承來源 Component)
Container

取得包含 IContainerComponent

(繼承來源 Component)
DesignMode

取得值,指出 Component 目前是否處於設計模式。

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。

(繼承來源 Component)
Icon

取得或設定要在狀態列面板內顯示的圖示。

MinWidth

取得或設定 StatusBar 控制項內允許的狀態列面板最小寬度。

Name

取得或設定要套用至 StatusBarPanel 的名稱。

Parent

取得裝載狀態列面板的 StatusBar 控制項。

Site

取得或設定 ComponentISite

(繼承來源 Component)
Style

取得或設定狀態列面板的樣式。

Tag

取得或設定包含 StatusBarPanel 相關資料的物件。

Text

取得或設定狀態列面板的文字。

ToolTipText

取得或設定與狀態列面板相關的工具提示文字。

Width

取得或設定 StatusBar 控制項內、狀態列面板的寬度。

方法

BeginInit()

開始初始化 StatusBarPanel

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。

(繼承來源 Component)
Dispose(Boolean)

釋放 StatusBarPanel 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

EndInit()

結束初始化 StatusBarPanel

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。

(繼承來源 Component)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
ToString()

擷取字串,其中包含面板的相關資訊。

事件

Disposed

Dispose() 方法的呼叫處置元件時,就會發生。

(繼承來源 Component)

適用於

另請參閱