Solved

Capturing F keystroke inside a form in VB.NET

Posted on 2011-09-13
4
437 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
Comment Utility
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
Comment Utility
Enable the KeyPreview property of the form and capture the keypress in the KeyDown event of the form
0
 

Author Closing Comment

by:pvg1975
Comment Utility
I was missing keypreview.

Thanks guys!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
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…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

14 Experts available now in Live!

Get 1:1 Help Now