ToolBarButtonClickEventArgs Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Attenzione
ToolBar is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use ToolStrip instead.
Fornisce dati per l'evento 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
- Ereditarietà
- Attributi
Esempio
Nell'esempio seguente viene creata un'istanza di e ToolBar tre ToolBarButton controlli. I pulsanti della barra degli strumenti vengono assegnati all'insieme di pulsanti, l'insieme viene assegnato alla barra degli strumenti e la barra degli strumenti viene aggiunta al modulo. Nell'evento ButtonClick della barra degli strumenti, la Button proprietà dell'oggetto ToolBarButtonClickEventArgs viene valutata e viene aperta la finestra di dialogo appropriata. Questo codice presuppone che sia stata creata un'istanza SaveFileDialogOpenFileDialogdi Form, un oggetto , e .PrintDialog
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
Commenti
L'evento si verifica ogni volta che l'utente fa clic su un pulsante su un ToolBar controllo . La Button proprietà contiene con ToolBarButton le informazioni sul pulsante su cui è stato fatto clic.
Costruttori
| Nome | Descrizione |
|---|---|
| ToolBarButtonClickEventArgs(ToolBarButton) |
Obsoleti.
Inizializza una nuova istanza della classe ToolBarButtonClickEventArgs. |
Proprietà
| Nome | Descrizione |
|---|---|
| Button |
Obsoleti.
Ottiene o imposta l'oggetto ToolBarButton su cui è stato fatto clic. |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Obsoleti.
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetHashCode() |
Obsoleti.
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetType() |
Obsoleti.
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Obsoleti.
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Obsoleti.
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |