StatusBar.StatusBarPanelCollection.Add 方法

定義

StatusBarPanel 加入集合。

多載

Add(String)

將含有指定文字的 StatusBarPanel 加入集合中。

Add(StatusBarPanel)

StatusBarPanel 加入集合。

Add(String)

將含有指定文字的 StatusBarPanel 加入集合中。

public:
 virtual System::Windows::Forms::StatusBarPanel ^ Add(System::String ^ text);
public virtual System.Windows.Forms.StatusBarPanel Add (string text);
abstract member Add : string -> System.Windows.Forms.StatusBarPanel
override this.Add : string -> System.Windows.Forms.StatusBarPanel
Public Overridable Function Add (text As String) As StatusBarPanel

參數

text
String

要加入的 StatusBarPanel 之文字。

傳回

StatusBarPanel

StatusBarPanel,表示加入至集合中的面板。

備註

您可以將面板新增至 StatusBar 控制項,以顯示一種以上的資訊類型。 這個版本的 Add 方法會使用 參數中指定的 text 文字建立新的 StatusBarPanel ,並將它新增至集合。 面板位於 StatusBar.StatusBarPanelCollection 中的順序代表面板顯示在控制項內 StatusBar 的順序。 面板會從左至右顯示,從集合中的第一個面板開始。 控制項 RightToLeftStatusBar 屬性不會變更面板中顯示 StatusBar 的順序。 若要在集合中的特定位置插入面板,請使用 Insert 方法。 若要在單一作業中將一組面板新增至集合,請使用 AddRange 方法。

另請參閱

適用於

Add(StatusBarPanel)

StatusBarPanel 加入集合。

public:
 virtual int Add(System::Windows::Forms::StatusBarPanel ^ value);
public virtual int Add (System.Windows.Forms.StatusBarPanel value);
abstract member Add : System.Windows.Forms.StatusBarPanel -> int
override this.Add : System.Windows.Forms.StatusBarPanel -> int
Public Overridable Function Add (value As StatusBarPanel) As Integer

參數

value
StatusBarPanel

StatusBarPanel,表示要加入至集合中的面板。

傳回

Int32

集合中項目以零為基底的索引。

例外狀況

要加入集合中的 StatusBarPanelnull

指定於 value 參數內之 StatusBarPanel 的父代 (Parent) 不是 null

範例

下列程式碼範例會在表單上建立 控制項,並新增兩 StatusBarPanelStatusBar 物件。 名為 的其中 StatusBarPanel 一個 物件 panel1 會顯示應用程式的狀態文字。 第二 StatusBarPanel 個名為 panel2 的 會顯示目前的日期,並使用 ToolTipText 類別的 StatusBarPanel 屬性來顯示目前的時間。 此範例會 ShowPanels 使用 屬性來確保顯示面板,而不是標準面板,而且會使用 和 Panels 屬性來存取 Add 的 方法 StatusBar.StatusBarPanelCollection ,以將面板新增至 StatusBar 。 此範例也會使用 AutoSizeBorderStyle ToolTipTextText 屬性來初始化 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

備註

您可以將面板新增至 StatusBar 控制項,以顯示一種以上的資訊類型。 這個版本的 Add 方法會將 參數中指定的 value 加入 StatusBarPanel 至集合。 面板位於 StatusBar.StatusBarPanelCollection 中的順序代表面板顯示在控制項內 StatusBar 的順序。 面板會從左至右顯示,從集合中的第一個面板開始。 控制項 RightToLeftStatusBar 屬性不會變更面板中顯示 StatusBar 的順序。 若要在集合中的特定位置插入面板,請使用 Insert 方法。 若要在單一作業中將一組面板新增至集合,請使用 AddRange 方法。

另請參閱

適用於