Keyboard shortcuts VB.NET
I m creating a VB.NET application and i want to create a keyboard shortcut to insert a dat but i want the shortcut to be ctrl-;
Now i have a hidden button with caption &; ... but this is Alt-; .
so how can i do this with ctrl instead of Alt?
tnx in advance
Re: Keyboard shortcuts VB.NET
I would set the form's key preview to true and then use the key down event of the form to run the code. The example below is a hidden button on a form although it doesn't really need to have the keyboard shortcut thingy set because this code will always respond to the user pressing Ctrl + C. If the button is hidden, I'm not sure why you would care about the shortcut, but that's beside the point....give it a whirl and let me know how you get on!
VB Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.Control = True Then
Select Case e.KeyCode
Case Keys.C
Button1_Click(Button1, New EventArgs)
End Select
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("Hello World")
End Sub
Re: Keyboard shortcuts VB.NET
this doesn't seem to work when the focus is on a textbox for example.
But i used the code on the keydown event of the textbox i wanted to insert the date in.
tnx a lot
Re: Keyboard shortcuts VB.NET
I have an addressbook that also has the add button to add additional records. Instead of pressing the tab key while entering information in every textbox, how can I use the keydownpress for each textbox if a user enters information so it can scroll to the next textbox?
Also having a login page instead of using the tab keypress, I would like to use the enter keypress to login after entering the username and password. How can I use in code for the keypress.
Re: Keyboard shortcuts VB.NET
you can do it like this with the keypress event.
Private Sub txtPass_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPass.KeyPress
If Asc(e.KeyChar) = 13 Then
'''here comes the code you want to execute
End If
End Sub