ToolStrip.ItemClicked ToolStrip.ItemClicked ToolStrip.ItemClicked ToolStrip.ItemClicked Event

定義

發生於按一下 ToolStripItem 時。Occurs when the ToolStripItem is clicked.

public:
 event System::Windows::Forms::ToolStripItemClickedEventHandler ^ ItemClicked;
public event System.Windows.Forms.ToolStripItemClickedEventHandler ItemClicked;
member this.ItemClicked : System.Windows.Forms.ToolStripItemClickedEventHandler 
Public Custom Event ItemClicked As ToolStripItemClickedEventHandler 

範例

下列程式碼範例示範如何使用這個成員。The following code example demonstrates the use of this member. 在範例中,事件處理常式會報告一次ItemClicked事件。In the example, an event handler reports on the occurrence of the ItemClicked event. 此報表可協助您了解事件發生的時機,並可協助您偵錯。This report helps you to learn when the event occurs and can assist you in debugging. 若要報告多個事件或事件經常發生,請考慮更換MessageBox.Show具有Console.WriteLine或將訊息附加到多行TextBoxTo report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要執行範例程式碼,將它貼到包含類型的執行個體的專案ToolStrip名為ToolStrip1To run the example code, paste it into a project that contains an instance of type ToolStrip named ToolStrip1. 請確定 與關聯的事件處理常式ItemClicked事件。Then ensure that the event handler is associated with the ItemClicked event.

private void ToolStrip1_ItemClicked(Object sender, ToolStripItemClickedEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ClickedItem", e.ClickedItem );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "ItemClicked Event" );
}
Private Sub ToolStrip1_ItemClicked(sender as Object, e as ToolStripItemClickedEventArgs) _ 
     Handles ToolStrip1.ItemClicked

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

End Sub

備註

如需有關如何處理事件的詳細資訊,請參閱 < 處理和引發事件For more information about handling events, see Handling and Raising Events.

適用於