重要
StatusStrip コントロールと ToolStripStatusLabel コントロールは、StatusBar コントロールと StatusBarPanel コントロールに機能を置き換えて追加します。ただし、StatusBar コントロールと StatusBarPanel コントロールは、下位互換性と将来の使用の両方で保持されます (選択した場合)。
ユーザーのクリックに応答するように StatusBar コントロール コントロールをプログラムするには、PanelClick イベント内で case ステートメントを使用します。 このイベントには、クリックされた StatusBarPanelへの参照を含む引数 (パネル引数) が含まれています。 このリファレンスを使用して、クリックされたパネルのインデックスを決定し、それに応じてプログラムすることができます。
手記
StatusBar コントロールの ShowPanels プロパティが true
に設定されていることを確認します。
どのパネルがクリックされたかを確認するには
PanelClick イベント ハンドラーで、
Select Case
(Visual Basic の場合) またはswitch case
(Visual C# または Visual C++) ステートメントを使用して、イベント引数のクリックされたパネルのインデックスを調べることで、どのパネルがクリックされたかを判断します。次のコード例では、StatusBar コントロール、
StatusBar1
、および 2 つの StatusBarPanel オブジェクト (StatusBarPanel1
とStatusBarPanel2
) のフォーム上に存在する必要があります。Private Sub StatusBar1_PanelClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.StatusBarPanelClickEventArgs) Handles StatusBar1.PanelClick Select Case StatusBar1.Panels.IndexOf(e.StatusBarPanel) Case 0 MessageBox.Show("You have clicked Panel One.") Case 1 MessageBox.Show("You have clicked Panel Two.") End Select End Sub
private void statusBar1_PanelClick(object sender, System.Windows.Forms.StatusBarPanelClickEventArgs e) { switch (statusBar1.Panels.IndexOf(e.StatusBarPanel)) { case 0 : MessageBox.Show("You have clicked Panel One."); break; case 1 : MessageBox.Show("You have clicked Panel Two."); break; } }
private: void statusBar1_PanelClick(System::Object ^ sender, System::Windows::Forms::StatusBarPanelClickEventArgs ^ e) { switch (statusBar1->Panels->IndexOf(e->StatusBarPanel)) { case 0 : MessageBox::Show("You have clicked Panel One."); break; case 1 : MessageBox::Show("You have clicked Panel Two."); break; } }
(Visual C#、Visual C++)フォームのコンストラクターに次のコードを配置して、イベント ハンドラーを登録します。
this.statusBar1.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler (this.statusBar1_PanelClick);
this->statusBar1->PanelClick += gcnew System::Windows::Forms::StatusBarPanelClickEventHandler (this, &Form1::statusBar1_PanelClick);
参照事項
.NET Desktop feedback