--- title: Determine Which Panel in StatusBar Control Was Clicked ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" helpviewer_keywords: - "status bars [Windows Forms], determining panel clicked" - "panels [Windows Forms], determining clicked" - "StatusBar control [Windows Forms], coding panel click events" - "StatusBar control [Windows Forms], determining panel clicked" - "PanelClick event [Windows Forms], determining panel clicked" - "Panel control [Windows Forms], determining click" ms.assetid: d14c6092-04b2-4a07-8ddf-0dd11277ff5f --- # How to: Determine Which Panel in the Windows Forms StatusBar Control Was Clicked > [!IMPORTANT] > The and controls replace and add functionality to the and controls; however, the and controls are retained for both backward compatibility and future use, if you choose. To program the [StatusBar Control](statusbar-control-windows-forms.md) control to respond to user clicks, use a case statement within the event. The event contains an argument (the panel argument), which contains a reference to the clicked . Using this reference, you can determine the index of the clicked panel, and program accordingly. > [!NOTE] > Ensure that the control's property is set to `true`. ### To determine which panel was clicked 1. In the event handler, use a `Select Case` (in Visual Basic) or `switch case` (Visual C# or Visual C++) statement to determine which panel was clicked by examining the index of the clicked panel in the event arguments. The following code example requires the presence, on the form, of a control, `StatusBar1`, and two objects, `StatusBarPanel1` and `StatusBarPanel2`. ```vb 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 ``` ```csharp 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; } } ``` ```cpp 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++) Place the following code in the form's constructor to register the event handler. ```csharp this.statusBar1.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler (this.statusBar1_PanelClick); ``` ```cpp this->statusBar1->PanelClick += gcnew System::Windows::Forms::StatusBarPanelClickEventHandler (this, &Form1::statusBar1_PanelClick); ``` ## See also - - - [How to: Set the Size of Status-Bar Panels](how-to-set-the-size-of-status-bar-panels.md) - [Walkthrough: Updating Status Bar Information at Run Time](walkthrough-updating-status-bar-information-at-run-time.md) - [StatusBar Control Overview](statusbar-control-overview-windows-forms.md)