Newbie question- use F10 to make save happen

I have a simple form, that has a save button.

I would like the "F10" key to be able to Save as well.  

Any help greatly appreciated.
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Another way via ProcessCmdKey()...

Public Class Form1
    Inherits System.Windows.Forms.Form

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If (msg.WParam.ToInt32 = Keys.F10) Then
            ButtonSave_Click(Nothing, Nothing)
            Return True
        End If
        Return False
    End Function

    Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
        MsgBox("Simulated Save...")
    End Sub

End Class
softplusConnect With a Mentor Commented:
The easiest way would be to use a menu, just define a Shortcut for the menu item (F10)

The harder way would be to handle the Keydown-events for the form, i.e.
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyData = Keys.F10 Then
            ' do whatever
            e.Handled = True
        End If
    End Sub
down0041Author Commented:
Thank you.  This is exactly what I needed.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.