ToolStrip.ItemAdded Zdarzenie

Definicja

Występuje po dodaniu nowego ToolStripItem elementu do elementu ToolStripItemCollection.

public:
 event System::Windows::Forms::ToolStripItemEventHandler ^ ItemAdded;
public event System.Windows.Forms.ToolStripItemEventHandler ItemAdded;
public event System.Windows.Forms.ToolStripItemEventHandler? ItemAdded;
member this.ItemAdded : System.Windows.Forms.ToolStripItemEventHandler 
Public Custom Event ItemAdded As ToolStripItemEventHandler 

Typ zdarzenia

Przykłady

W poniższym przykładzie kodu pokazano użycie tego elementu członkowskiego. W tym przykładzie program obsługi zdarzeń zgłasza wystąpienie ItemAdded zdarzenia. Ten raport pomaga dowiedzieć się, kiedy wystąpi zdarzenie, i może pomóc w debugowaniu. Aby zgłosić wiele zdarzeń lub często występujących zdarzeń, rozważ zastąpienie MessageBox.Show komunikatu ciągiem Console.WriteLine lub dołączenie go do wielowierszowego TextBoxelementu .

Aby uruchomić przykładowy kod, wklej go w projekcie zawierającym wystąpienie typu ToolStrip o nazwie ToolStrip1. Następnie upewnij się, że program obsługi zdarzeń jest skojarzony ze zdarzeniem ItemAdded .

private void ToolStrip1_ItemAdded(Object sender, ToolStripItemEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Item", e.Item );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "ItemAdded Event" );
}
Private Sub ToolStrip1_ItemAdded(sender as Object, e as ToolStripItemEventArgs) _ 
     Handles ToolStrip1.ItemAdded

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Item", e.Item)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"ItemAdded Event")

End Sub

Uwagi

Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i podnoszenie zdarzeń.

Dotyczy