Partager via


ToolBarButtonClickEventArgs Classe

Définition

Attention

ToolBar is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use ToolStrip instead.

Fournit des données pour l’événement ButtonClick.

public ref class ToolBarButtonClickEventArgs : EventArgs
public class ToolBarButtonClickEventArgs : EventArgs
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`ToolBar` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ToolStrip` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public class ToolBarButtonClickEventArgs : EventArgs
type ToolBarButtonClickEventArgs = class
    inherit EventArgs
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`ToolBar` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ToolStrip` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
type ToolBarButtonClickEventArgs = class
    inherit EventArgs
Public Class ToolBarButtonClickEventArgs
Inherits EventArgs
Héritage
ToolBarButtonClickEventArgs
Attributs

Exemples

L’exemple suivant instancie un ToolBar et trois ToolBarButton contrôles. Les boutons de barre d’outils sont affectés à la collection de boutons, la collection est affectée à la barre d’outils et la barre d’outils est ajoutée au formulaire. Dans l’événement ButtonClick de la barre d’outils, la Button propriété de la ToolBarButtonClickEventArgs barre d’outils est évaluée et la boîte de dialogue appropriée ouverte. Ce code suppose qu’un Form, un OpenFileDialog, un SaveFileDialog, et un ont PrintDialog été instanciés.

public:
   void InitializeMyToolBar()
   {
      // Create and initialize the ToolBar and ToolBarButton controls.
      toolBar1 = gcnew ToolBar;
      ToolBarButton^ toolBarButton1 = gcnew ToolBarButton;
      ToolBarButton^ toolBarButton2 = gcnew ToolBarButton;
      ToolBarButton^ toolBarButton3 = gcnew ToolBarButton;
      
      // Set the Text properties of the ToolBarButton controls.
      toolBarButton1->Text = "Open";
      toolBarButton2->Text = "Save";
      toolBarButton3->Text = "Print";
      
      // Add the ToolBarButton controls to the ToolBar.
      toolBar1->Buttons->Add( toolBarButton1 );
      toolBar1->Buttons->Add( toolBarButton2 );
      toolBar1->Buttons->Add( toolBarButton3 );
      
      // Add the event-handler delegate.
      toolBar1->ButtonClick += gcnew ToolBarButtonClickEventHandler(
         this, &Form1::toolBar1_ButtonClick );
      
      // Add the ToolBar to the Form.
      Controls->Add( toolBar1 );
   }

private:
   void toolBar1_ButtonClick(
      Object^ sender,
      ToolBarButtonClickEventArgs^ e )
   {
      // Evaluate the Button property to determine which button was clicked.
      switch ( toolBar1->Buttons->IndexOf( e->Button ) )
      {
         case 0:
            openFileDialog1->ShowDialog();
            // Insert code to open the file.
            break;
         case 1:
            saveFileDialog1->ShowDialog();
            // Insert code to save the file.
            break;
         case 2:
            printDialog1->ShowDialog();
            // Insert code to print the file.    
            break;
      }
   }
public void InitializeMyToolBar()
 {
    // Create and initialize the ToolBar and ToolBarButton controls.
    toolBar1 = new ToolBar();
    ToolBarButton toolBarButton1 = new ToolBarButton();
    ToolBarButton toolBarButton2 = new ToolBarButton();
    ToolBarButton toolBarButton3 = new ToolBarButton();
 
    // Set the Text properties of the ToolBarButton controls.
    toolBarButton1.Text = "Open";
    toolBarButton2.Text = "Save";
    toolBarButton3.Text = "Print";
 
    // Add the ToolBarButton controls to the ToolBar.
    toolBar1.Buttons.Add(toolBarButton1);
    toolBar1.Buttons.Add(toolBarButton2);
    toolBar1.Buttons.Add(toolBarButton3);
    
    // Add the event-handler delegate.
    toolBar1.ButtonClick += new ToolBarButtonClickEventHandler (
       this.toolBar1_ButtonClick);
    
    // Add the ToolBar to the Form.
    Controls.Add(toolBar1);
 }
 
 private void toolBar1_ButtonClick (
                         Object sender, 
                         ToolBarButtonClickEventArgs e)
 {
   // Evaluate the Button property to determine which button was clicked.
   switch(toolBar1.Buttons.IndexOf(e.Button))
   {
      case 0:
         openFileDialog1.ShowDialog();
         // Insert code to open the file.
         break; 
      case 1:
         saveFileDialog1.ShowDialog();
         // Insert code to save the file.
         break; 
      case 2:
         printDialog1.ShowDialog();
         // Insert code to print the file.    
         break; 
    }
 }
Public Sub InitializeMyToolBar()
    ' Create and initialize the ToolBar and ToolBarButton controls.
    Dim toolBar1 As New ToolBar()
    Dim toolBarButton1 As New ToolBarButton()
    Dim toolBarButton2 As New ToolBarButton()
    Dim toolBarButton3 As New ToolBarButton()
    
    ' Set the Text properties of the ToolBarButton controls.
    toolBarButton1.Text = "Open"
    toolBarButton2.Text = "Save"
    toolBarButton3.Text = "Print"
    
    ' Add the ToolBarButton controls to the ToolBar.
    toolBar1.Buttons.Add(toolBarButton1)
    toolBar1.Buttons.Add(toolBarButton2)
    toolBar1.Buttons.Add(toolBarButton3)
    
    ' Add the event-handler delegate.
    AddHandler toolBar1.ButtonClick, AddressOf Me.toolBar1_ButtonClick
    
    ' Add the ToolBar to the Form.
    Controls.Add(toolBar1)
End Sub    

Private Sub toolBar1_ButtonClick(ByVal sender As Object, _
ByVal e As ToolBarButtonClickEventArgs)

    ' Evaluate the Button property to determine which button was clicked.
    Select Case toolBar1.Buttons.IndexOf(e.Button)
        Case 0
            openFileDialog1.ShowDialog()
            ' Insert code to open the file.
        Case 1
            saveFileDialog1.ShowDialog()
            ' Insert code to save the file.
        Case 2
            printDialog1.ShowDialog()
            ' Insert code to print the file.
    End Select
End Sub

Remarques

L’événement se produit chaque fois que l’utilisateur clique sur un bouton sur un ToolBar contrôle. La Button propriété contient les ToolBarButton informations sur le bouton qui a été cliqué.

Constructeurs

Nom Description
ToolBarButtonClickEventArgs(ToolBarButton)
Obsolète.

Initialise une nouvelle instance de la classe ToolBarButtonClickEventArgs.

Propriétés

Nom Description
Button
Obsolète.

Obtient ou définit le ToolBarButton clic qui a été cliqué.

Méthodes

Nom Description
Equals(Object)
Obsolète.

Détermine si l’objet spécifié est égal à l’objet actuel.

(Hérité de Object)
GetHashCode()
Obsolète.

Sert de fonction de hachage par défaut.

(Hérité de Object)
GetType()
Obsolète.

Obtient la Type de l’instance actuelle.

(Hérité de Object)
MemberwiseClone()
Obsolète.

Crée une copie superficielle du Objectactuel.

(Hérité de Object)
ToString()
Obsolète.

Retourne une chaîne qui représente l’objet actuel.

(Hérité de Object)

S’applique à

Voir aussi