StatusBar.StatusBarPanelCollection.Add メソッド

定義

コレクションに StatusBarPanel を追加します。

オーバーロード

名前 説明
Add(String)

指定したテキストを持つ StatusBarPanel をコレクションに追加します。

Add(StatusBarPanel)

コレクションに StatusBarPanel を追加します。

Add(String)

ソース:
StatusBar.StatusBarPanelCollection.cs
ソース:
StatusBar.StatusBarPanelCollection.cs

指定したテキストを持つ 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

注釈

StatusBar コントロールにパネルを追加して、複数の種類の情報を表示できます。 このバージョンの Add メソッドは、StatusBarPanel パラメーターで指定されたテキストを使用して新しいtextを作成し、コレクションに追加します。 パネルが StatusBar.StatusBarPanelCollection に配置される順序は、パネルが StatusBar コントロール内に表示される順序を表します。 パネルは、コレクション内の最初のパネルから左から右に表示されます。 RightToLeft コントロールの StatusBar プロパティは、パネルがStatusBarに表示される順序を変更しません。 コレクション内の特定の位置にパネルを挿入するには、 Insert メソッドを使用します。 1 回の操作で一連のパネルをコレクションに追加するには、 AddRange メソッドを使用します。

こちらもご覧ください

適用対象

Add(StatusBarPanel)

ソース:
StatusBar.StatusBarPanelCollection.cs
ソース:
StatusBar.StatusBarPanelCollection.cs

コレクションに 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

返品

コレクション内の項目の 0 から始まるインデックス。

例外

コレクションに追加される StatusBarPanelnullされました。

StatusBarPanel パラメーターで指定されたvalueの親がnullされていません。

次のコード例では、フォームに StatusBar コントロールを作成し、2 つの StatusBarPanel オブジェクトを追加します。 StatusBarPanelという名前のpanel1 オブジェクトの 1 つに、アプリケーションの状態テキストが表示されます。 StatusBarPanelという名前の 2 番目のpanel2は、現在の日付を表示し、ToolTipText クラスの StatusBarPanel プロパティを使用して現在の時刻を表示します。 この例では、ShowPanels プロパティを使用して、パネルが標準パネルではなく表示されるようにし、Panels プロパティを使用してAddStatusBar.StatusBarPanelCollection メソッドにアクセスしてパネルをStatusBarに追加します。 また、この例では、 AutoSizeBorderStyleToolTipText、および Text プロパティを使用して、 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 メソッドは、StatusBarPanel パラメーターで指定されたvalueをコレクションに追加します。 パネルが StatusBar.StatusBarPanelCollection に配置される順序は、パネルが StatusBar コントロール内に表示される順序を表します。 パネルは、コレクション内の最初のパネルから左から右に表示されます。 RightToLeft コントロールの StatusBar プロパティは、パネルがStatusBarに表示される順序を変更しません。 コレクション内の特定の位置にパネルを挿入するには、 Insert メソッドを使用します。 1 回の操作で一連のパネルをコレクションに追加するには、 AddRange メソッドを使用します。

こちらもご覧ください

適用対象