Procedura: aggiungere pannelli a un controllo StatusBarHow to: Add Panels to a StatusBar Control

Importante

Il StatusStrip e ToolStripStatusLabel controlli sostituire e aggiungere funzionalità a di StatusBar e StatusBarPanel controlli; tuttavia, il StatusBar e StatusBarPanel vengono mantenuti per compatibilità con le versioni precedenti e per utilizzo futuro, se si Scegliere.The StatusStrip and ToolStripStatusLabel controls replace and add functionality to the StatusBar and StatusBarPanel controls; however, the StatusBar and StatusBarPanel controls are retained for both backward compatibility and future use, if you choose.

L'area programmabile all'interno di un controllo StatusBar controllo è costituito da istanze del StatusBarPanel classe.The programmable area within a StatusBar Control control consists of instances of the StatusBarPanel class. Questi vengono aggiunti tramite le aggiunte per la StatusBar.StatusBarPanelCollection classe.These are added through additions to the StatusBar.StatusBarPanelCollection class.

Per aggiungere pannelli a una barra di statoTo add panels to a status bar

  1. In una routine, creare pannelli della barra di stato aggiungendoli al file il StatusBar.StatusBarPanelCollection.In a procedure, create status-bar panels by adding them to the StatusBar.StatusBarPanelCollection. Specificare le impostazioni di proprietà per singoli pannelli utilizzando il relativo indice passato tramite la Panels proprietà.Specify property settings for individual panels by using its index passed through the Panels property.

    Nell'esempio di codice riportato di seguito, il percorso impostato per la posizione dell'icona è il documenti cartella.In the following code example, the path set for the location of the icon is the My Documents folder. Questo percorso viene utilizzato perché è possibile presupporre che la maggior parte dei computer che eseguono il sistema operativo Windows sarà inclusa in questa cartella.This location is used because you can assume that most computers running the Windows operating system will include this folder. Questa scelta consente anche agli utenti con livelli di accesso di sistema minimi eseguire in modo sicuro l'applicazione.Choosing this location also allows users with minimal system access levels to safely run the application. L'esempio seguente richiede un form con un StatusBar controllo già aggiunto.The following example requires a form with a StatusBar control already added.

    Nota

    Il StatusBar.StatusBarPanelCollection è una raccolta in base zero, il codice deve procedere di conseguenza.The StatusBar.StatusBarPanelCollection is a zero-based collection, so code should proceed accordingly.

    Public Sub CreateStatusBarPanels()  
    ' Create panels and set text property.  
       StatusBar1.Panels.Add("One")  
       StatusBar1.Panels.Add("Two")  
       StatusBar1.Panels.Add("Three")  
    ' Set properties of StatusBar panels.  
    ' Set AutoSize property of panels.  
       StatusBar1.Panels(0).AutoSize = StatusBarPanelAutoSize.Spring  
       StatusBar1.Panels(1).AutoSize = StatusBarPanelAutoSize.Contents  
       StatusBar1.Panels(2).AutoSize = StatusBarPanelAutoSize.Contents  
    ' Set BorderStyle property of panels.  
       StatusBar1.Panels(0).BorderStyle = StatusBarPanelBorderStyle.Raised  
       StatusBar1.Panels(1).BorderStyle = StatusBarPanelBorderStyle.Sunken  
       StatusBar1.Panels(2).BorderStyle = StatusBarPanelBorderStyle.Raised  
    ' Set Icon property of third panel. You should replace the bolded  
    ' icon in the sample below with an icon of your own choosing.  
       StatusBar1.Panels(2).Icon = New _   
       System.Drawing.Icon(System.Environment.GetFolderPath _  
       (System.Environment.SpecialFolder.Personal) _  
       & "\Icon.ico")  
       StatusBar1.ShowPanels = True  
    End Sub  
    
    public void CreateStatusBarPanels()  
    {  
       // Create panels and set text property.  
       statusBar1.Panels.Add("One");  
       statusBar1.Panels.Add("Two");  
       statusBar1.Panels.Add("Three");  
       // Set properties of StatusBar panels.  
       // Set AutoSize property of panels.  
       statusBar1.Panels[0].AutoSize = StatusBarPanelAutoSize.Spring;  
       statusBar1.Panels[1].AutoSize = StatusBarPanelAutoSize.Contents;  
       statusBar1.Panels[2].AutoSize = StatusBarPanelAutoSize.Contents;  
       // Set BorderStyle property of panels.  
       statusBar1.Panels[0].BorderStyle =  
          StatusBarPanelBorderStyle.Raised;  
       statusBar1.Panels[1].BorderStyle = StatusBarPanelBorderStyle.Sunken;  
       statusBar1.Panels[2].BorderStyle = StatusBarPanelBorderStyle.Raised;  
       // Set Icon property of third panel. You should replace the bolded  
       // icon in the sample below with an icon of your own choosing.  
       // Note the escape character used (@) when specifying the path.  
       statusBar1.Panels[2].Icon =   
          new System.Drawing.Icon (System.Environment.GetFolderPath _  
       (System.Environment.SpecialFolder.Personal) _  
       + @"\Icon.ico");  
       statusBar1.ShowPanels = true;  
    }  
    
    public:  
       void CreateStatusBarPanels()  
       {  
          // Create panels and set text property.  
          statusBar1->Panels->Add("One");  
          statusBar1->Panels->Add("Two");  
          statusBar1->Panels->Add("Three");  
          // Set properties of StatusBar panels.  
          // Set AutoSize property of panels.  
          statusBar1->Panels[0]->AutoSize =  
             StatusBarPanelAutoSize::Spring;  
          statusBar1->Panels[1]->AutoSize =  
             StatusBarPanelAutoSize::Contents;  
          statusBar1->Panels[2]->AutoSize =  
             StatusBarPanelAutoSize::Contents;  
          // Set BorderStyle property of panels.  
          statusBar1->Panels[0]->BorderStyle =  
             StatusBarPanelBorderStyle::Raised;  
          statusBar1->Panels[1]->BorderStyle =  
             StatusBarPanelBorderStyle::Sunken;  
          statusBar1->Panels[2]->BorderStyle =  
             StatusBarPanelBorderStyle::Raised;  
          // Set Icon property of third panel.  
          // You should replace the bolded image   
          // in the sample below with an icon of your own choosing.  
          statusBar1->Panels[2]->Icon =  
             gcnew System::Drawing::Icon(String::Concat(  
             System::Environment::GetFolderPath(  
             System::Environment::SpecialFolder::Personal),  
             "\\Icon.ico"));  
          statusBar1->ShowPanels = true;  
       }  
    

Vedere ancheSee Also

StatusBar
ToolStripStatusLabel
Finestra di dialogo Editor della raccoltaCollection Editor Dialog Box
Procedura: Impostare la dimensione dei pannelli della barra di statoHow to: Set the Size of Status-Bar Panels
Procedura dettagliata: Aggiornamento delle informazioni sulla barra di stato in fase di esecuzioneWalkthrough: Updating Status Bar Information at Run Time
Procedura: Individuare il pannello selezionato nel controllo StatusBar di Windows FormHow to: Determine Which Panel in the Windows Forms StatusBar Control Was Clicked
Cenni preliminari sul controllo StatusBarStatusBar Control Overview