Hai...

How to Usercontrols with Shortcut Keys[F1,F2,F3,CTRL+O]...

I am creating one windows apllication..

the apllication contain many form..

in one form i am used one usercontrol(parent control)..

the many form used in that inherited usercontrol(child control)..

in my form i want to use shorcut keys

in usercontrol form does not have keypreview property..

so i am use the shortcut function keys

i have add,edit,delete,and search for various button in my usercontrol form

i want to put the shorcut key to each every buttons

this is my code..this nopt worked..

Private Sub frmTemplate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

Try

If (e.KeyCode = Keys.F1) And mblnAddEnable = True Then

btnAdd_Click(sender, e)

ElseIf (e.KeyCode = Keys.F2) And mblnEditEnable = True Then

btnEdit_Click(sender, e)

ElseIf e.KeyCode = Keys.F3 And mblnDelEnable = True Then

btnDelete_Click(sender, e)

ElseIf e.KeyCode = Keys.F7 Then

btnCancel_Click(sender, e)

ElseIf e.KeyCode = Keys.F6 And mblnAdd = False And mblnEdit = False Then

btnFilter_Click(sender, e)

End If

If e.KeyCode = Keys.Enter Then

SendKeys.Send("{Tab}")

End If

Catch ex As Exception

msgbox(ex.Message.ToString())

End Try

End Sub

I am not have the keypreview property in desinging mode..

please help me..

how to use the shortcut keys

please reply me..........

im pretty sure this is because the user control wont have focus as it is simply a control whereas the MAIN FORM will have focus. Simplest way i can think of doing this is to put your methods to listen for the keypresses in your main form. Make your methods PUBLIC in your user control and on keypress in your main form reference the method i.e.

Private Sub MAINFORM_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    USERCONTROL.whatyouwantmetodo()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.