Cara Membuat ShortCut F1,F2...... atau CTRL,ALT,SHIFT pada Vb..net

Letakan property ini di event form_load



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
End Sub

kemudian simpan semua sintak new, save, cancel, close anda di event form_keydown

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.F2 'new
                '...sintak anda
            Case Keys.F5 'save
                '...sintak anda
            Case Keys.F6 'cancel
                '...sintak anda
            Case Keys.F7 'close
                '...sintak anda
        End Select
End Sub
 
atau anda bisa menulisnya seperti ini :


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyValue
            Case 113 'new
                '...sintak anda
            Case 116 'save
                '...sintak anda
            Case 117 'cancel
                '...sintak anda
            Case 118 'close
                '...sintak anda
        End Select
End Sub

Berikut ini daftar keyvalue dari F1 sampai F12 :
112 = F1
113 = F2
114 = F3
115 = F4
116 = F5
117 = F6
118 = F7
119 = F8
120 = F9
121 = F10
122 = F11
123 = F12

Jika anda ingin menggabungkan KEY seperti CTRL+S atau ALT+A atau ALT+SHIFT+D atau terserah anda, maka cukup tulis codenya seperti ini (contoh CTRL+SHIFT+ALT+Z) :


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    If e.Alt And e.Shift And e.Control And e.KeyCode = Keys.Z Then
        MessageBox.Show("OK !!!")
    End If
End Sub
 
 
 
Sumber : Djiesoft

Comments

Popular Posts