Solved

make F2 when pressed

Posted on 2008-06-25
4
220 Views
Last Modified: 2010-04-23
I have a form , if the user press F2 within the form whenever he is (any control within the form)
if he press f2 to do some thing , like savebuttom.performclick
0
Comment
Question by:Ahmadal_najjar2003
  • 2
4 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 21870410
Is this what you want ?
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

        If e.KeyCode = Keys.Insert Then

            Button1.PerformClick()

        End If

    End Sub
 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.KeyPreview = True

    End Sub

Open in new window

0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 21870411
Just replace Keys.Insert with Keys.F2
0
 
LVL 27

Expert Comment

by:planocz
ID: 21875010
Place this sample in your form and it will capture the keys you want.
  Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean

        Const WM_KEYDOWN As Integer = &H100

        Const WM_SYSKEYDOWN As Integer = &H104
 

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then

            Select Case (keyData)

                Case Keys.A To Keys.Z                                '<--- Catch the Keys you want

                    MessageBox.Show("You pressed " & ChrW(keyData))  '<--- Then do something

                Case Keys.Right

                    Me.Text = "Right Arrow Captured"

                Case Keys.Left

                    Me.Text = "Left Arrow Captured"

                Case Keys.Down

                    Me.Text = "Down Arrow Captured"

                Case Keys.Up

                    Me.Text = "Up Arrow Captured"

                Case Keys.Tab

                    Me.Text = "Tab Key Captured"

                Case (Keys.Control Or Keys.N)

                    Me.Text = "<CTRL> + N Captured"

                Case (Keys.Alt Or Keys.Z)

                    Me.Text = "<ALT> + Z Captured"

                Case Keys.NumPad0

                    Me.Text = "Num Pad '0' Captured"

                Case Keys.Delete

                    MessageBox.Show("Delete Captured")

                Case Keys.NumLock

            End Select

        End If
 

        Return MyBase.ProcessCmdKey(msg, keyData)

    End Function

Open in new window

0
 

Author Closing Comment

by:Ahmadal_najjar2003
ID: 31470792
Thank alot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

26 Experts available now in Live!

Get 1:1 Help Now