StatusBarPanel 類別

定義

代表 StatusBar 控制項中的面板。Represents a panel in a StatusBar control. 雖然 StatusStrip 控制項會在前幾個版本的 StatusBar 控制項中取代並新增功能,您還是可以選擇保留 StatusBar 以提供回溯相容性 (Backward Compatibility) 或供未來使用。Although the StatusStrip control replaces and adds functionality to the StatusBar control of previous versions, StatusBar is retained for both backward compatibility and future use if you choose.

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
繼承
實作

範例

下列程式碼範例會在表單上建立 StatusBar 控制項,並加入兩個 StatusBarPanel 物件。The following code example creates a StatusBar control on a form and adds two StatusBarPanel objects. 第一個名為 panel1StatusBarPanel會顯示應用程式的狀態文字。The first StatusBarPanel, named panel1, displays status text for an application. 第二個名為 panel2StatusBarPanel會顯示目前的日期,並使用 StatusBarPanel 類別的 ToolTipText 屬性來顯示目前的時間。The second StatusBarPanel, named panel2, displays the current date and uses the ToolTipText property of the StatusBarPanel class to display the current time. 這個範例會使用 ShowPanels 屬性來確保顯示面板,而不是標準面板,而且它會使用 Panels 屬性來存取 StatusBar.StatusBarPanelCollectionAdd 方法,以將面板加入至 StatusBarThe example uses the ShowPanels property to ensure that the panels are displayed instead of a standard panel, and it uses the Panels property to access the Add method of the StatusBar.StatusBarPanelCollection to add the panels to the StatusBar. 此範例也會使用 AutoSizeBorderStyleToolTipTextText 屬性來初始化 StatusBarPanel 物件。The example also uses the AutoSize, BorderStyle, ToolTipText, and Text properties to initialize the StatusBarPanel objects. 這個範例假設已定義範例中定義的方法,並從 Form的構造函式呼叫。This example assumes that the method defined in the example is defined and called from the constructor of a 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

備註

StatusBarPanel 代表 StatusBar 控制項 StatusBar.StatusBarPanelCollection 中的個別面板。A StatusBarPanel represents an individual panel in the StatusBar.StatusBarPanelCollection of a StatusBar control. StatusBarPanel 可以包含文字和(或)可用於反映應用程式狀態的圖示。A StatusBarPanel can contain text and/or an icon that can be used to reflect the status of an application. 使用 StatusBar.StatusBarPanelCollection(可透過 StatusBar 控制項的 StatusBar.Panels 屬性存取)來抓取、加入或移除個別的 StatusBarPanelUse the StatusBar.StatusBarPanelCollection, accessible through the StatusBar.Panels property of a StatusBar control, to retrieve, add, or remove an individual StatusBarPanel.

StatusBarPanel 提供屬性,可讓您在 StatusBar 控制項中修改面板的顯示行為。The StatusBarPanel provides properties that enable you to modify the display behavior of a panel within a StatusBar control. 您可以使用 [Icon] 屬性,在面板中顯示圖示。You can use the Icon property to display an icon within a panel. 這個屬性可以用來提供應用程式中狀態的圖形表示。This property can be used to provide a graphical representation of state in an application. Alignment 屬性可讓您指定文字和/或圖示在面板中對齊的方式。The Alignment property enables you to specify how text and/or an icon is aligned within the panel. 若要確保您的面板會適當調整大小以符合面板的文字,您可以使用 [AutoSize] 屬性自動調整面板的大小,以符合面板的文字,或填滿 [StatusBar] 控制項內的剩餘空間。To ensure that your panel is sized properly to fit the text of the panel, you can use the AutoSize property to automatically resize the panel to fit the text of the panel or to fill the remaining space within the StatusBar control. [MinWidth] 屬性可讓您指定面板的最小寬度,以確保它不會小於要顯示的資料。The MinWidth property enables you to specify a minimum width for the panel to ensure that it does not get smaller than the data it is intended to display.

StatusBar 控制項通常用來顯示應用程式的說明資訊或狀態資訊。The StatusBar control is typically used to display Help information or state information about your application. 通常,請務必顯示面板中所呈現之資料的其他資訊。Often, it is important to display additional information about data that is presented in a panel. 您可以使用 [ToolTipText] 屬性,在滑鼠指標停留在面板上時顯示資訊。You can use the ToolTipText property to display information whenever the mouse pointer rests on a panel.

雖然 StatusBar 控制項通常用來顯示文字資訊,但您也可以將自己的顯示類型提供給 StatusBarPanelAlthough the StatusBar control is typically used to display textual information, you can also provide your own type of display to a StatusBarPanel. Style 屬性可讓您指定如何繪製 StatusBarPanelThe Style property enables you to specify how the StatusBarPanel will be drawn. 根據預設,Style 屬性會用來顯示 Text 屬性的值(如果在 Icon 屬性中指定,則會使用圖示)。By default, the Style property is used to display the value of the Text property (and an icon, if specified in the Icon property). 如果屬性設定為 [OwnerDraw],您可以在面板中繪製您自己的資訊。If the property is set to OwnerDraw, you can draw your own information into the panel. 您可以使用這項功能,在面板中繪製進度列或動畫圖標。You can use this feature to draw a progress bar or an animated icon in the panel.

當您建立 StatusBarPanel 類別的實例時,讀取/寫入屬性會設定為初始值。When you create an instance of the StatusBarPanel class, the read/write properties are set to initial values. 如需這些值的清單,請參閱 StatusBarPanel 的函式。For a list of these values, see the StatusBarPanel constructor.

建構函式

StatusBarPanel()

初始化 StatusBarPanel 類別的新執行個體。Initializes a new instance of the StatusBarPanel class.

屬性

Alignment

取得或設定狀態列面板內文字與圖示的對齊方式。Gets or sets the alignment of text and icons within the status bar panel.

AutoSize

取得或設定值,指出狀態列面板是否會自動調整大小。Gets or sets a value indicating whether the status bar panel is automatically resized.

BorderStyle

取得或設定狀態列面板的框線樣式。Gets or sets the border style of the status bar panel.

CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(繼承來源 Component)
Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(繼承來源 Component)
DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(繼承來源 Component)
Icon

取得或設定要在狀態列面板內顯示的圖示。Gets or sets the icon to display within the status bar panel.

MinWidth

取得或設定 StatusBar 控制項內允許的狀態列面板最小寬度。Gets or sets the minimum allowed width of the status bar panel within the StatusBar control.

Name

取得或設定要套用至 StatusBarPanel 的名稱。Gets or sets the name to apply to the StatusBarPanel.

Parent

取得裝載狀態列面板的 StatusBar 控制項。Gets the StatusBar control that hosts the status bar panel.

Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(繼承來源 Component)
Style

取得或設定狀態列面板的樣式。Gets or sets the style of the status bar panel.

Tag

取得或設定包含 StatusBarPanel 相關資料的物件。Gets or sets an object that contains data about the StatusBarPanel.

Text

取得或設定狀態列面板的文字。Gets or sets the text of the status bar panel.

ToolTipText

取得或設定與狀態列面板相關的工具提示文字。Gets or sets ToolTip text associated with the status bar panel.

Width

取得或設定 StatusBar 控制項內、狀態列面板的寬度。Gets or sets the width of the status bar panel within the StatusBar control.

方法

BeginInit()

開始初始化 StatusBarPanelBegins the initialization of a StatusBarPanel.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。Releases all resources used by the Component.

(繼承來源 Component)
Dispose(Boolean)

釋放 StatusBarPanel 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the StatusBarPanel and optionally releases the managed resources.

EndInit()

結束初始化 StatusBarPanelEnds the initialization of a StatusBarPanel.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(繼承來源 Component)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
ToString()

擷取字串,其中包含面板的相關資訊。Retrieves a string that contains information about the panel.

事件

Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(繼承來源 Component)

適用於

另請參閱