Updated: August 2010
Gets or sets a value indicating whether the key event should be passed on to the underlying control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Syntax . . :: . Boolean
true if the key event should not be sent to the control; otherwise, false.
Public Property SuppressKeyPress As Booleanpublic bool SuppressKeyPress { get; set; }public:
property bool SuppressKeyPress {
bool get ();
void set (bool value);
}member SuppressKeyPress : bool with get, set
Property Value
Type: Systemtrue 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 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
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 && e.Modifiers != Keys.Shift)
{
e.SuppressKeyPress = true;
}
}
Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.