How do you use the keyboard keys in the form? Tutorial

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
6 posts Page 1 of 1
Contributors
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 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.
Code: Select all
    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
Now as you can see it works and you can change the keys.enter to keys.space or keys.b or whatever you need.

Thanks for looking at this tutorial!
Sincerely,
Harley
[Information Technologist in training, New to the whole VB coding]
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

good job
but these are called hotkeys
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 am

oh they are? my bad.
Sincerely,
Harley
[Information Technologist in training, New to the whole VB coding]
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

just saying so you can get more views on topic im not mad or nothing just telling cooll;
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 am

oh i know but I was just saying my bad because i didn't know
Sincerely,
Harley
[Information Technologist in training, New to the whole VB coding]
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

oh ok
lol :D
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
6 posts Page 1 of 1
Return to “Tutorials”