Using one of the F keys to trigger an event

Respondida Using one of the F keys to trigger an event

  • Thursday, December 04, 2008 2:36 PM
     
     

    Is there a way to trigger an event when the end user presses one of the F keys? For instance I am already using one of my buttons as the Acceptbutton. What I would like to do is if the user presses say F11 it will trigger another button on my form and run the code. Any suggestions? I am using C#

All Replies

  • Thursday, December 04, 2008 2:46 PM
     
     Answered

     

    Hi Marty,

     

    Here is your solution.

     

    Set KeyPreview = True of Form.

    Then in KeyDown Event of Form write following code.

     

    Code Snippet

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

    Try

    If e.KeyCode = Keys.F11 Then

    MsgBox("Function 1")  '''''Here you can write your own code.

    End If

    Catch ex As Exception

    End Try

    End Sub

     

     

    If your requirement is different or if i misunderestood then let me know.

     

    Thank You

     

    Best Regards

    Utkarsh Gajjar.

  • Thursday, December 04, 2008 3:04 PM
     
     
     Marty Q wrote:

    Is there a way to trigger an event when the end user presses one of the F keys? For instance I am already using one of my buttons as the Acceptbutton. What I would like to do is if the user presses say F11 it will trigger another button on my form and run the code. Any suggestions? I am using C#

     

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/bb3de05c-d635-4246-b065-8a06ff6e02d0

     

    Duplicate post.

  • Thursday, December 04, 2008 3:30 PM
     
     

    You are good. That worked perfectly thanks.