Solved

Capturing F keystroke inside a form in VB.NET

Posted on 2011-09-13
4
439 Views
Last Modified: 2012-05-12
Hi,

Is it possible to capture, for example, F5 keystroke on a form even if the focus is on a textbox?

I need to capture F5 on a form independently of the control that has the focus.

Thanks!
0
Comment
Question by:pvg1975
4 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 400 total points
ID: 36530936
The simple way to do this is using form.keypreview.  Setting this property true sends all key presses to the form level  handler:
Form.KeyPreview Property
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
    End Sub
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.F5 Then
            MsgBox("F5")
            'If this is false, then keypress is sent on to focus control
            e.Handled = True
        End If


    End Sub


End Class

Open in new window

0
 
LVL 17

Assisted Solution

by:nepaluz
nepaluz earned 100 total points
ID: 36530949
Enable the KeyPreview property of the form and capture the keypress in the KeyDown event of the form
0
 

Author Closing Comment

by:pvg1975
ID: 36530971
I was missing keypreview.

Thanks guys!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36531014
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Variable Event ? 3 27
vb.net help 4 29
Get number of Files in Directory and Sub Directories 2 39
i have to take the screenshot of command prompt? how to do this? 1 35
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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