KeyEventArgs.SuppressKeyPress 属性

定义

获取或设置一个值,该值指示是否应将键事件传递给基础控件。

public:
 property bool SuppressKeyPress { bool get(); void set(bool value); };
public bool SuppressKeyPress { get; set; }
member this.SuppressKeyPress : bool with get, set
Public Property SuppressKeyPress As Boolean

属性值

true 如果不应将键事件发送到控件,则为否则,为 false.

示例

下面的代码示例阻止数值击键到达名为的TextBoxtextBox1控件。

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 && e.Modifiers != Keys.Shift)
    {
        e.SuppressKeyPress = true;
    }
}
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    
    If e.KeyCode >= Keys.D0 And e.KeyCode <= Keys.D9 And _
    e.Modifiers <> Keys.Shift Then
        e.SuppressKeyPress = True
    End If
End Sub

注解

可以在事件处理程序中分配给 true 此属性,例如 KeyDown 为了防止用户输入。

设置为 SuppressKeyPresstrueHandled 也设置为 true.

适用于

另请参阅