반응형

* VBNET 윈도우 폼(Window Form) - Control, Shift, Alt 키 조합 키 입력 받기 (단축키) 예제...

 

전체 소스 코드

Form1.vb

 

 

= 첫번째 방법

- Form KeyDown 이벤트를 받아서 구현 해 주는 방법

- Form  속성 -> keyPreview 를 true를 해 줍니다.

 

 

Public Class Form1

    Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.Modifiers = Keys.Control Then
            Select Case e.KeyCode
                Case Keys.S
                    'Control + S 조합 임
                    MessageBox.Show("Control + S 키를 입력 하였습니다.", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)

            End Select
        ElseIf e.Modifiers = Keys.Alt Then
            Select Case e.KeyCode
                Case Keys.Enter
                    'Alt + Enter 조합 임
                    MessageBox.Show("Alt + Enter 키를 입력 하였습니다.", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)

            End Select
        Else
            Select Case e.KeyCode
                Case Keys.F5
                    MessageBox.Show("F5 키를 입력 하였습니다.", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)

            End Select
        End If
    End Sub


End Class

 

= 두번째 방법

 

Public Class Form1

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

        Dim key As Keys = keyData And Not (Keys.Shift Or Keys.Control Or Keys.Alt)

        Select Case key
            Case Keys.S

                If (keyData And Keys.Control) <> 0 Then
                    MessageBox.Show("Control + S 키를 입력 하였습니다.", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                End If

                Exit Select
            Case Keys.F5
                MessageBox.Show("F5 키를 입력 하였습니다.", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                Exit Select
            Case Keys.Tab

                If (keyData And Keys.Shift) <> 0 Then
                    MessageBox.Show("Shift + Tab 키를 입력 하였습니다.", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                End If

                Exit Select
            Case Keys.Enter

                If (keyData And Keys.Alt) <> 0 Then
                    MessageBox.Show("Alt + Enter 키를 입력 하였습니다.", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                End If

                Exit Select
        End Select



        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

End Class

*예제 결과

 

 

 

https://kdsoft-zeros.tistory.com/147

 

[C#] 윈도우 폼(Window Form) - Control, Shift , Alt 키 조합 키 입력 받기 (단축키)

* C# 윈도우 폼(Window Form) - Control, Shift, Alt 키 조합 키 입력 받기 (단축키) 예제... 전체 소스 코드 Form1.cs = 첫번째 방법 using System; using System.Collections.Generic; using System.ComponentM..

kdsoft-zeros.tistory.com

 

반응형

+ Recent posts