다음을 통해 공유


KeyPressEventArgs.Handled 속성

KeyPress 이벤트가 처리되었는지 여부를 나타내는 값을 가져오거나 설정합니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Property Handled As Boolean
‘사용 방법
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)

속성 값

이벤트가 처리되었으면 true이고, 그렇지 않으면 false입니다.

설명

이벤트가 처리되지 않은 경우 기본 처리를 위해 운영 체제로 전달됩니다. KeyPress 이벤트를 취소하려면 Handledtrue로 설정합니다.

예제

다음 예제에서는 TextBox 컨트롤을 만듭니다. keypressed 메서드는 KeyChar 속성을 사용하여 Enter 키를 눌렀는지 여부를 확인합니다. ENTER 키를 눌렀으면 Handled 속성이 true로 설정되어 이벤트가 처리됨을 나타냅니다.

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

플랫폼

Windows 98, Windows 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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

KeyPressEventArgs 클래스
KeyPressEventArgs 멤버
System.Windows.Forms 네임스페이스
Control.KeyPress 이벤트