Breyta

Deila með


KeyEventArgs.SuppressKeyPress Property

Definition

Gets or sets a value indicating whether the key event should be passed on to the underlying control.

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

Property Value

true if the key event should not be sent to the control; otherwise, false.

Examples

The following code example prevents numeric keystrokes from reaching the TextBox control named textBox1.

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

Remarks

You can assign true to this property in an event handler such as KeyDown in order to prevent user input.

Setting SuppressKeyPress to true also sets Handled to true.

Applies to

See also