KeyPressEventArgs.Handled Property
.NET Framework 3.0
Gets or sets a value indicating whether the KeyPress event was handled.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Assembly: System.Windows.Forms (in system.windows.forms.dll)
The following example creates a TextBox control. The keypressed method uses the KeyChar property to check whether the ENTER key is pressed. If the ENTER key is pressed, the Handled property is set to true, which indicates the event is handled.
using System; using System.Windows.Forms; public class Form1: Form { public Form1() { // Create a TextBox control. TextBox tb = new TextBox(); this.Controls.Add(tb); tb.KeyPress += new KeyPressEventHandler(keypressed); } private void keypressed(Object o, KeyPressEventArgs e) { // The keypressed method uses the KeyChar property to check // whether the ENTER key is pressed. // If the ENTER key is pressed, the Handled property is set to true, // to indicate the event is handled. if (e.KeyChar == (char)Keys.Return) { e.Handled = true; } } public static void Main() { Application.Run(new Form1()); } }
import System.*;
import System.Windows.Forms.*;
public class Form1 extends Form
{
public Form1()
{
// Create a TextBox control.
TextBox tb = new TextBox();
this.get_Controls().Add(tb);
tb.add_KeyPress(new KeyPressEventHandler(KeyPressed));
} //Form1
void KeyPressed(Object o, KeyPressEventArgs e)
{
// The keypressed method uses the KeyChar property to check
// whether the ENTER key is pressed.
// If the ENTER key is pressed, the Handled property is set to true,
// to indicate the event is handled.
if (e.get_KeyChar() == (char)(13)) {
e.set_Handled(true);
}
} // KeyPressed
public static void main(String[] args)
{
Application.Run(new Form1());
} //main
} //Form1
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.