Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my code is :
VB
'Private Sub ExpenseMaster_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

 '    If (e.KeyCode = Keys.S && e.Control) Then


   '        Save.PerformClick()
   '    End If
   '
   'End Sub

Help me out how to enable ctrl + s in vb.net?

I have also tried SendKeys.Send(^{s}) to get short cut enabled.
Please help me out.
Posted
Updated 18-Sep-10 9:41am
v2
Comments
Richard MacCutchan 18-Sep-10 15:49pm    
Since all the above is a comment it is unlikely to do anything, let alone what you are asking for!

This works for me.

Excuse the code style please, I'm not used to VB.Net

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    MessageBox.Show("Save Called")
End Sub
Private Sub Button1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyDown
    If e.Control Then
        If e.KeyCode = Keys.S Then
            Button1.PerformClick()
        End If
    End If
End Sub


I have just noticed that you want a lower case 's', so modify my code appropriately.
 
Share this answer
 
v2
Comments
parchuri08 21-Sep-10 4:30am    
Ctrl+S button code you had given really helped as i kept that code in form_keydown event . I got the output. Thanx a lot.
Private Sub GroupMaster_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Control Then
If e.KeyCode = Keys.S Then
Save.PerformClick()
End If
If e.KeyCode = Keys.N Then
Button1.PerformClick()
End If

If e.KeyCode = Keys.E Then
Edit.PerformClick()
End If
If e.KeyCode = Keys.D Then
Cancel.PerformClick()
End If
End If
End Sub
I also kept me.Keypreview = true
in page load event. then it executed correctly
add below code in page load

Me.KeyPreview = True
 
Share this answer
 
Comments
parchuri08 21-Sep-10 4:21am    
The code u posted for page load event really helped me.. Now I am able to access shortcut buttons
parchuri08 21-Sep-10 4:30am    
Thanx a ton

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900