4
Contributors
13
Replies
14
Views
6 Years
Discussion Span
Last Post by aadi_capri
Featured Replies
0

hello mr das,
actually what exactly i want is, when i click L on my keyboard then all the code written in label1_click even is executed.....i have tried using what you have posted ba its not working....
newaz THANX.

0

I did exactly what debasisdas posted and it does exactly what you want.

You do need to set your form's KeyPreview property to true. On the designer click on your form and in the properties window find KeyPreview and set it to true. Or in the load event you could add Me.KeyPreview = True .

Public Class Form1

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

    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If e.KeyChar = "l" Then
            Label1_Click(Label1, EventArgs.Empty)
        End If
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        MsgBox("L")
    End Sub

End Class
0

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

its giving an error on me.keypress and hence not running.

0

cant we use a keydown event?
earlier in my project i have used keydown event to be invoked on the button shortcuts.

Private Sub Form3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.l Then
Me.KeyPreview = False
Button1.PerformClick()
End If
End Sub

0

hello every1,
i jst changed the handles me.keypress to handles mybase.keypress
and now its working......
thanx every1 for your help.
and
IT WAS GIVING ERROR on 'me' as "keyword is not a valid identifier".

0

oops sry ...new to this site.........and m finding this site very useful:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.