Solved

make F2 when pressed

Posted on 2008-06-25
4
221 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL syntax in VB.net 5 39
Extracting last characters in a substring 5 26
Help with exporting to excel 4 25
Sending receiving text messages in vb.net 15 32
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

813 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

8 Experts available now in Live!

Get 1:1 Help Now