[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

A simple msgbox by pressing keyboard

Dear EE,

I have a simple form with a button named:

btnA

well... if I clicked btnA , it will invoke a function call test()

My Question is.....

How can I make a very simple event.... if I pressed "A" in the KEYBOARD key it will invoke test()

How can I make it??
0
joely2k
Asked:
joely2k
  • 5
  • 5
1 Solution
 
DabasCommented:
Hi joely2k:
YOu can capture one of the form's key events, such as KeyDown

Dabas
0
 
joely2kAuthor Commented:
   Private Sub btnCreate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles btnCreate.KeyDown
        If e.KeyCode = Keys.A Then
            MsgBox("test")
        End If
    End Sub


Hi Thanks it works... but then why when I pressed the second time.. it wont work??
0
 
DabasCommented:
Try to change the code so that it uses the FORM's KeyDown event.
Probably the second time, the focus was not on the button anymore.

Dabas
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
joely2kAuthor Commented:
I did tried my main form but it cannot...

    Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.B Then
            MsgBox("Why you hit B")
        End If
    End Sub

Neway actually is better if I can use no button... just a simple keyboard pressed will trigger and event for all the time? possible?
0
 
joely2kAuthor Commented:
Ok can already thanks you so much
0
 
DabasCommented:
Try setting the Form's KeyPreview Property to True
0
 
joely2kAuthor Commented:
what is the keypreview for?
0
 
DabasCommented:
For a B grade to a 25 point question you can probably find it out yourself using help!

Cheers!
0
 
joely2kAuthor Commented:
Thanks you alot....

I understand helping is just for points...

enjoy life, see ya
0
 
DabasCommented:
joely2k:
LOL. I have enough points.
Na, its not "just the points".
Its the principle!


Dabas
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now