ToolStripDropDown.KeyPress Zdarzenie

Definicja

Występuje po naciśnięciu klawisza, gdy element ToolStripDropDown ma fokus.

public:
 event System::Windows::Forms::KeyPressEventHandler ^ KeyPress;
[System.ComponentModel.Browsable(false)]
public event System.Windows.Forms.KeyPressEventHandler KeyPress;
[System.ComponentModel.Browsable(false)]
public event System.Windows.Forms.KeyPressEventHandler? KeyPress;
[<System.ComponentModel.Browsable(false)>]
member this.KeyPress : System.Windows.Forms.KeyPressEventHandler 
Public Custom Event KeyPress As KeyPressEventHandler 

Typ zdarzenia

Atrybuty

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 KeyPress 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 ToolStripDropDown o nazwie ToolStripDropDown1. Następnie upewnij się, że program obsługi zdarzeń jest skojarzony ze zdarzeniem KeyPress .

private void ToolStripDropDown1_KeyPress(Object sender, KeyPressEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "KeyChar", e.KeyChar );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Handled", e.Handled );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "KeyPress Event" );
}
Private Sub ToolStripDropDown1_KeyPress(sender as Object, e as KeyPressEventArgs) _ 
     Handles ToolStripDropDown1.KeyPress

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

End Sub

Uwagi

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

Dotyczy