StatusBar.StatusBarPanelCollection.Add Méthode

Définition

Ajoute un StatusBarPanel à la collection.

Surcharges

Add(String)

Ajoute un StatusBarPanel contenant le texte spécifié à la collection.

Add(StatusBarPanel)

Ajoute un StatusBarPanel à la collection.

Add(String)

Ajoute un StatusBarPanel contenant le texte spécifié à la collection.

public:
 virtual System::Windows::Forms::StatusBarPanel ^ Add(System::String ^ text);
public virtual System.Windows.Forms.StatusBarPanel Add (string text);
abstract member Add : string -> System.Windows.Forms.StatusBarPanel
override this.Add : string -> System.Windows.Forms.StatusBarPanel
Public Overridable Function Add (text As String) As StatusBarPanel

Paramètres

text
String

Texte de StatusBarPanel qui est ajouté.

Retours

StatusBarPanel

StatusBarPanel qui représente le panneau ajouté à la collection.

Remarques

Vous pouvez ajouter des panneaux à un StatusBar contrôle pour afficher plusieurs types d’informations. Cette version de la Add méthode crée une nouvelle StatusBarPanel version avec le texte spécifié dans le paramètre et l’ajoute à la text collection. Ordre dans lequel les panneaux se trouvent dans l’ordre StatusBar.StatusBarPanelCollection d’affichage des panneaux dans le StatusBar contrôle. Les panneaux sont affichés de gauche à droite à partir du premier panneau de la collection. La RightToLeft propriété du StatusBar contrôle ne modifie pas l’ordre dans lequel les panneaux sont affichés dans le StatusBar. Pour insérer un panneau à une position spécifique dans la collection, utilisez la Insert méthode. Pour ajouter un ensemble de panneaux à la collection dans une seule opération, utilisez la AddRange méthode.

Voir aussi

S’applique à

Add(StatusBarPanel)

Ajoute un StatusBarPanel à la collection.

public:
 virtual int Add(System::Windows::Forms::StatusBarPanel ^ value);
public virtual int Add (System.Windows.Forms.StatusBarPanel value);
abstract member Add : System.Windows.Forms.StatusBarPanel -> int
override this.Add : System.Windows.Forms.StatusBarPanel -> int
Public Overridable Function Add (value As StatusBarPanel) As Integer

Paramètres

value
StatusBarPanel

StatusBarPanel qui représente le panneau à ajouter à la collection.

Retours

Int32

Index de base zéro de l'élément dans la collection.

Exceptions

StatusBarPanel ajouté à la collection était null.

Le parent du StatusBarPanel spécifié dans le paramètre value n'est pas null.

Exemples

L’exemple de code suivant crée un StatusBar contrôle sur un formulaire et ajoute deux StatusBarPanel objets. L’un des StatusBarPanel objets, nommé panel1, affiche le texte d’état d’une application. Le deuxième StatusBarPanel, nommé panel2, affiche la date actuelle et utilise la ToolTipText propriété de la StatusBarPanel classe pour afficher l’heure actuelle. L’exemple utilise la ShowPanels propriété pour s’assurer que les panneaux sont affichés au lieu d’un panneau standard, et qu’il utilise et la Panels propriété pour accéder à la Add méthode de l’élément StatusBar.StatusBarPanelCollection pour ajouter les panneaux au StatusBar. L’exemple utilise également les propriétés , BorderStyleet Text ToolTipTextles AutoSizepropriétés pour initialiser les StatusBarPanel objets. Cet exemple suppose que la méthode définie dans l’exemple est définie et appelée à partir du constructeur d’un Form.

private:
   void CreateMyStatusBar()
   {
      // Create a StatusBar control.
      StatusBar^ statusBar1 = gcnew StatusBar;

      // Create two StatusBarPanel objects to display in the StatusBar.
      StatusBarPanel^ panel1 = gcnew StatusBarPanel;
      StatusBarPanel^ panel2 = gcnew 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 time the application
      // was started.
      panel2->ToolTipText = System::DateTime::Now.ToShortTimeString();

      // Set the text of the panel to the current date.
      panel2->Text = "Started: " + 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 );
   }
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 time the application was started.
    panel2.ToolTipText = "Started: " + 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);
}
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 time the application was started.
   panel2.ToolTipText = "Started: " & 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

Remarques

Vous pouvez ajouter des panneaux à un StatusBar contrôle pour afficher plusieurs types d’informations. Cette version de la Add méthode ajoute le StatusBarPanel paramètre spécifié value à la collection. Ordre dans lequel les panneaux se trouvent dans l’ordre StatusBar.StatusBarPanelCollection d’affichage des panneaux dans le StatusBar contrôle. Les panneaux sont affichés de gauche à droite à partir du premier panneau de la collection. La RightToLeft propriété du StatusBar contrôle ne modifie pas l’ordre dans lequel les panneaux sont affichés dans le StatusBar. Pour insérer un panneau à une position spécifique dans la collection, utilisez la Insert méthode. Pour ajouter un ensemble de panneaux à la collection dans une seule opération, utilisez la AddRange méthode.

Voir aussi

S’applique à