ToolStripControlHost.KeyPress イベント

定義

ホストされるコントロールにフォーカスがあるときにキーが押されると発生します。

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

イベントの種類

次のコード例では、このメンバーの使用方法を示します。 この例では、イベント ハンドラーがイベントの KeyPress 発生を報告します。 このレポートは、イベントが発生したタイミングを知るのに役立ち、デバッグに役立ちます。 複数のイベントまたは頻繁に発生するイベントを報告するには、 を Console.WriteLine に置き換えるかMessageBox.Show、複数行TextBoxにメッセージを追加することを検討してください。

コード例を実行するには、 という名前ToolStripControlHost1の型ToolStripControlHostのインスタンスを含むプロジェクトに貼り付けます。 次に、イベント ハンドラーが イベントに関連付けられていることを確認します KeyPress

private void ToolStripControlHost1_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 ToolStripControlHost1_KeyPress(sender as Object, e as KeyPressEventArgs) _ 
     Handles ToolStripControlHost1.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

注釈

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。

適用対象

こちらもご覧ください