Shortcut Keys in Visual Basic
Hi, I was wondering about how to apply shortcut keys (like control+c and control+v) in visual basic
There was a thread on this I found but I tried all the codes and variations but nothing worked, like nothing would happen when I pressed the keys
could someone give me the code about how to activate a "control+t" and a "control+r" control? thanks
the farthest I got was:
private sub form3_key down...........handles form3.keydown
if e.keycodes = keys.control and e.keycodes = keys.t then
msgbox("hi")
end if
end sub
I that was the best looking code I got, but it didn't work
i also did
For Each item As Control In Me.Controls
AddHandler item.KeyDown, AddressOf Form3_KeyDown
Next
i noticed if I did code for just pressing the control key it worked but when I tried to use two keys it didnt'
Re: Shortcut Keys in Visual Basic
Did you set the KeyPreview property of the form to true?
Re: Shortcut Keys in Visual Basic
e.keydata should give you the codes you're looking for. Try this and see the different results:
Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
lblCode.Text = e.KeyCode
lblData.Text = e.KeyData
lblValue.Text = e.KeyValue
End Sub
e.keydata should reflect the ctrl+key combination.
Re: Shortcut Keys in Visual Basic
You can use Andalso for that :
Code:
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.Control = True AndAlso e.KeyCode = Keys.D0 Then
MsgBox("manhit")
End If
End Sub
:rolleyes: