KeyPressEventArgs.Handled 속성
정의
public:
property bool Handled { bool get(); void set(bool value); };
public bool Handled { get; set; }
member this.Handled : bool with get, set
Public Property Handled As Boolean
속성 값
이벤트가 처리되었으면 true
이고, 그렇지 않으면 false
입니다.true
if the event is handled; otherwise, false
.
예제
다음 예제에서는 TextBox 제어 합니다.The following example creates a TextBox control. 합니다 keypressed
메서드는 KeyChar ENTER 키를 눌렀는지 여부를 확인할 속성입니다.The keypressed
method uses the KeyChar property to check whether the ENTER key is pressed. ENTER 키를 누르는 경우는 Handled 속성 true
, 처리 되는 이벤트를 나타냅니다.If the ENTER key is pressed, the Handled property is set to true
, which indicates the event is handled.
#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 );
}
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());
}
}
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
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
Public Shared Sub Main()
Application.Run(New Form1())
End Sub
End Class
설명
이벤트 처리 되지 않은 경우 기본 처리에 대 한 운영 체제에 보내집니다.If the event is not handled, it will be sent to the operating system for default processing. 설정 Handled 하 true
취소 하는 KeyPress
이벤트입니다.Set Handled to true
to cancel the KeyPress
event.