Newbie question- use F10 to make save happen

Posted on 2005-05-13
Last Modified: 2010-05-18
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.
Question by:down0041
    LVL 13

    Assisted Solution

    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
    LVL 85

    Accepted Solution

    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

    Author Comment

    Thank you.  This is exactly what I needed.  

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now