KeyPressEventArgs.Handled-Eigenschaft
Ruft einen Wert ab, der angibt, ob das KeyPress-Ereignis behandelt wurde, oder legt diesen fest.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Property Handled As Boolean
'Usage
Dim instance As KeyPressEventArgs
Dim value As Boolean
value = instance.Handled
instance.Handled = value
public bool Handled { get; set; }
public:
property bool Handled {
bool get ();
void set (bool value);
}
/** @property */
public boolean get_Handled ()
/** @property */
public void set_Handled (boolean value)
public function get Handled () : boolean
public function set Handled (value : boolean)
Eigenschaftenwert
true, wenn das Ereignis behandelt wurde, andernfalls false.
Hinweise
Wenn keine Behandlung des Ereignisses erfolgt, wird es für eine Standardverarbeitung an das Betriebssystem gesendet. Legen Sie Handled auf true fest, um das KeyPress-Ereignis abzubrechen.
Beispiel
Im folgenden Beispiel wird ein TextBox-Steuerelement erstellt. Die keypressed
-Methode verwendet die KeyChar-Eigenschaft, um zu prüfen, ob die EINGABETASTE gedrückt ist. Ist dies der Fall, wird die Handled-Eigenschaft auf true festgelegt, wodurch angegeben ist, dass das Ereignis behandelt wurde.
Imports System
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Public Sub New()
' Create a TextBox control.
Dim tb As New TextBox()
Me.Controls.Add(tb)
AddHandler tb.KeyPress, AddressOf keypressed
End Sub 'New
Private Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
' 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 = Microsoft.VisualBasic.ChrW(Keys.Return) Then
e.Handled = True
End If
End Sub 'keypressed
Public Shared Sub Main()
Application.Run(New Form1())
End Sub 'Main
End Class 'Form1
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());
}
}
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Windows::Forms;
public ref class Form1: public Form
{
public:
Form1()
{
// Create a TextBox control.
TextBox^ tb = gcnew TextBox;
this->Controls->Add( tb );
tb->KeyPress += gcnew KeyPressEventHandler( this, &Form1::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)13 )
e->Handled = true;
}
};
int main()
{
Application::Run( gcnew 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
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
KeyPressEventArgs-Klasse
KeyPressEventArgs-Member
System.Windows.Forms-Namespace
Control.KeyPress-Ereignis