How do you use the keyboard keys in the form? Tutorial
Posted: Tue Aug 10, 2010 2:51 am
Hello everyone..
Have you ever wondered how to get your form to do something by pressing a button on the keyboard? Well problem solved!
See here is a code I use for my web browser for my address bar so when I press enter it navigates although this is not what you are looking for it is the same idea.
Thanks for looking at this tutorial!
Have you ever wondered how to get your form to do something by pressing a button on the keyboard? Well problem solved!
See here is a code I use for my web browser for my address bar so when I press enter it navigates although this is not what you are looking for it is the same idea.
Code: Select all
Now as you can see it works and you can change the keys.enter to keys.space or keys.b or whatever you need. Private Sub ComboBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
If e.KeyCode = Keys.Enter Then
'Navigate to the current address.
If ComboBox1.Text = My.Settings.Blocked(Form3.ListBox1.SelectedItem) Then
MsgBox("This site has been blocked, to unblock it go under tools and blocked sites.", MsgBoxStyle.Critical)
Else
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(ComboBox1.Text)
End If
My.Settings.History.Add(ComboBox1.Text)
ListBox2.Items.Clear()
For Each Item As String In My.Settings.History
ListBox2.Items.Add(Item)
ComboBox1.Items.Add(Item)
Next
Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - Web Browser Elite"
'Prevent the sound that indicates an invalid key press.
e.SuppressKeyPress = True
End If
End Sub
Thanks for looking at this tutorial!