KeyEventArgs.SuppressKeyPress 속성

정의

키 이벤트를 기본 컨트롤에 전달할지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool SuppressKeyPress { bool get(); void set(bool value); };
public bool SuppressKeyPress { get; set; }
member this.SuppressKeyPress : bool with get, set
Public Property SuppressKeyPress As Boolean

속성 값

키 이벤트를 컨트롤로 보내지 않아야 하면

예제

다음 코드 예제에서는 숫자 키 입력이 명명TextBox된 컨트롤에 textBox1 도달하지 못하도록 합니다.

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 && e.Modifiers != Keys.Shift)
    {
        e.SuppressKeyPress = true;
    }
}
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

설명

사용자 입력을 방지하기 위해 이벤트 true 처리기에서 이 속성에 할당 KeyDown 할 수 있습니다.

또한 .로 설정하도록 SuppressKeyPresstrue 설정합니다 Handledtrue.

적용 대상

추가 정보