Results 1 to 14 of 14

Thread: key press event

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91

    key press event

    when someone pushes f12 an action takes place. how to do it?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Use KeyDown or KeyUp event .

    VB Code:
    1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    2.             If e.KeyData = Keys.F12 Then
    3.                 MessageBox.Show("You just pressed F12")
    4.             End If
    5. End Sub

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Set form's KeyPreview property in the Properties Explorer to True .

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    not workin

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    might it be mecause the combo box is selected?

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Synth3t1c
    not workin
    What do you mean not working ? Do you mean you want to set up a wide-system hotkey or what ?

    It's working here .

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Synth3t1c
    might it be mecause the combo box is selected?
    Even if the focus was in another control , it should trigger the event . I've just tested it .

  8. #8
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    VB Code:
    1. 'syn maybe you forgot to put this.
    2. KeyPreview = True

  9. #9
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    hello mate. not in combo. i don't know about upper than 2k2 but i don't get the keydown event of the form if the focus is in the combo.

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by brown monkey
    hello mate. not in combo. i don't know about upper than 2k2 but i don't get the keydown event of the form if the focus is in the combo.
    Are you sure you set the form's KeyPreview property in the Properties Explorer to True ?

  11. #11
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    yep

  12. #12
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Try this .
    Attached Files Attached Files

  13. #13
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    yep. it works. but it won't with the dropdownstyle of combobox1 is set to dropdown. works with the dropdownlist style.

  14. #14
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Damned B.M. !
    Once again you are right!
    I use Vs.Net 2003 but I have the same behaviour.
    I have a combo in DropDownStyle and...

    VB Code:
    1. Private Sub FrmRientri_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    2.         If MessageBox.Show(Me.CmbNumeroDocRientro.DropDownStyle.ToString & "    " & " I'm in KeyDown. Do you want to change in DropDown", "", MessageBoxButtons.YesNo) = DialogResult.Yes Then
    3.             Me.CmbNumeroDocRientro.DropDownStyle = ComboBoxStyle.DropDown
    4.         End If
    5.     End Sub

    as you can see my procedure show a message box when keydown event is fired. It remind me that is placed in keydown event and ask me if I want to change the style of combo. After two or three rounds I decided to change the style and..... from that moment my event was not more fired. It seems a bug, isn't it?
    Live long and prosper (Mr. Spock)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width