Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/determine-which-panel-wf-statusbar-control-was-clicked.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

4.4 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
Determine Which Panel in StatusBar Control Was Clicked 03/30/2017
csharp
vb
cpp
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
d14c6092-04b2-4a07-8ddf-0dd11277ff5f

How to: Determine Which Panel in the Windows Forms StatusBar Control Was Clicked

Important

The xref:System.Windows.Forms.StatusStrip and xref:System.Windows.Forms.ToolStripStatusLabel controls replace and add functionality to the xref:System.Windows.Forms.StatusBar and xref:System.Windows.Forms.StatusBarPanel controls; however, the xref:System.Windows.Forms.StatusBar and xref:System.Windows.Forms.StatusBarPanel controls are retained for both backward compatibility and future use, if you choose.

To program the StatusBar Control control to respond to user clicks, use a case statement within the xref:System.Windows.Forms.StatusBar.PanelClick event. The event contains an argument (the panel argument), which contains a reference to the clicked xref:System.Windows.Forms.StatusBarPanel. Using this reference, you can determine the index of the clicked panel, and program accordingly.

Note

Ensure that the xref:System.Windows.Forms.StatusBar control's xref:System.Windows.Forms.StatusBar.ShowPanels%2A property is set to true.

To determine which panel was clicked

  1. In the xref:System.Windows.Forms.StatusBar.PanelClick 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 xref:System.Windows.Forms.StatusBar control, StatusBar1, and two xref:System.Windows.Forms.StatusBarPanel objects, StatusBarPanel1 and 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++) Place the following code in the form's constructor to register the event handler.

    this.statusBar1.PanelClick += new
       System.Windows.Forms.StatusBarPanelClickEventHandler
       (this.statusBar1_PanelClick);  
    
    this->statusBar1->PanelClick += gcnew  
       System::Windows::Forms::StatusBarPanelClickEventHandler  
       (this, &Form1::statusBar1_PanelClick);  
    

See also