StatusBarPanel をコレクションに追加します。
Overloads Public Overridable Function Add( _
ByVal value As StatusBarPanel _) As Integer
[C#]
public virtual int Add(StatusBarPanelvalue);
[C++]
public: virtual int Add(StatusBarPanel* value);
[JScript]
public function Add(
value : StatusBarPanel) : int;
パラメータ
- value
コレクションに追加するパネルを表す StatusBarPanel 。
戻り値
コレクション内の項目の 0 から始まるインデックス番号。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | コレクションに追加されている StatusBarPanel が null でした。 |
ArgumentException | value パラメータで指定された StatusBarPanel の親が null ではありません。 |
解説
StatusBar コントロールにパネルを追加して、複数の種類の情報を表示できます。このバージョンの Add メソッドは、value パラメータで指定された StatusBarPanel オブジェクトをコレクションに追加します。 StatusBar.StatusBarPanelCollection 内のパネルの配置順序は、 StatusBar コントロール内でパネルが表示される順序を表します。パネルは、コレクション内の最初のパネルから始まり、左から右に表示されます。 StatusBar コントロールの RightToLeft プロパティは、 StatusBar 内のパネルの表示順序は変更しません。パネルをコレクションの特定の位置に挿入するには、 Insert メソッドを使用します。一連のパネルをコレクションに一度に追加するには、 AddRange メソッドを使用します。
使用例
[Visual Basic, C#, C++] フォームに StatusBar コントロールを作成し、2 つの StatusBarPanel オブジェクトを追加する例を次に示します。 StatusBarPanel オブジェクトの 1 つである panel1
は、アプリケーションのステータス テキストを表示します。 panel2
という名前の 2 番目の StatusBarPanel オブジェクトは、現在の日付を表示し、 StatusBarPanel クラスの ToolTipText プロパティを使用して現在の時刻を表示します。この例では、標準パネルの代わりにこれらのパネルが表示されるようにするために ShowPanels プロパティを使用し、さらに Panels プロパティを使用して StatusBar.StatusBarPanelCollection の Add メソッドにアクセスして StatusBar にパネルを追加します。また、 StatusBarPanel オブジェクトを初期化するために、 AutoSize 、 BorderStyle 、 ToolTipText 、 Text の各プロパティも使用します。この例は、コード内で定義されたメソッドが定義されており、 Form のコンストラクタから呼び出されることを前提にしています。
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 current time.
panel2.ToolTipText = 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
[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 the current time.
panel2.ToolTipText = 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);
}
[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 = S"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 current time.
panel2->ToolTipText = 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);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
StatusBar.StatusBarPanelCollection クラス | StatusBar.StatusBarPanelCollection メンバ | System.Windows.Forms 名前空間 | StatusBar.StatusBarPanelCollection.Add オーバーロードの一覧 | StatusBarPanel | AddRange | Insert