Show Dialig boxes with key_press or key_down event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mywork60
    New Member
    • Dec 2007
    • 5

    Show Dialig boxes with key_press or key_down event

    hi
    I'm working on a windows application form , I need to show dialog boxes by clicking a key on the keyboard , how can I do taht ?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    You need to handle the keystroke on Keydown / KeyPress event of particular control.

    Comment

    • !NoItAll
      Contributor
      • May 2006
      • 297

      #3
      First turn the forms KeyPreview property to True. This means the keydown event in the form will always see any keystroke. Without this you would have to check the keydown event in every control on the form - and it isn't practical to do this.

      Next - in the form you will find a keydown event. Keydown is receives more keystrokes than keypress. Keydown is the best place to check for the key you want. The values to test here are a bit cryptic - so the best way is to put a break point in here and look at the value of the keystroke return when you press the key you want.

      Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
      Dim iKey as Integer

      iKey = KeyCode 'run the form and test this for the keyvalue you want

      'then when you know the key you want use this code here
      If iKey = iKeyIWant then
      'do what you want
      End if

      End Sub

      Again - make sure the KeyPreview property of the form is TRUE.

      Comment

      Working...