Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Keyboard Events

Keyboard Events

Scheduled Pinned Locked Moved C#
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ShimiG
    wrote on last edited by
    #1

    Im having a trouble to catch KeyDown event on the form.. it just doesnt work.. any other control on the form can get KeyDown event if ill set it to him but the form event just doesnt work.. thanks..

    D 1 Reply Last reply
    0
    • S ShimiG

      Im having a trouble to catch KeyDown event on the form.. it just doesnt work.. any other control on the form can get KeyDown event if ill set it to him but the form event just doesnt work.. thanks..

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The form itself rarely ever has the focus. The controls on the form have it, so the form's KeyDown event is rarely ever called. Unless, that is, the Form's KeyPreview property is set to true. This will pass all the keyboard events going to the form's control with the focus to the form's handlers first, then pass them on to the control that has the focus. There is a side effect to setting this though. The KeyDown event will fire for every keystroke going to any control on your form. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The form itself rarely ever has the focus. The controls on the form have it, so the form's KeyDown event is rarely ever called. Unless, that is, the Form's KeyPreview property is set to true. This will pass all the keyboard events going to the form's control with the focus to the form's handlers first, then pass them on to the control that has the focus. There is a side effect to setting this though. The KeyDown event will fire for every keystroke going to any control on your form. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        S Offline
        S Offline
        ShimiG
        wrote on last edited by
        #3

        Thanks exactly what i was looking for ! they didnt mention that on MSDN..

        P D 2 Replies Last reply
        0
        • S ShimiG

          Thanks exactly what i was looking for ! they didnt mention that on MSDN..

          P Offline
          P Offline
          Patric_J
          wrote on last edited by
          #4

          Hi, I'm curious, why would a form need to catch keyboard events? What are you using it for? I can't think of any scenario where this can be used. /Patric My C# blog: C# Coach

          S 1 Reply Last reply
          0
          • P Patric_J

            Hi, I'm curious, why would a form need to catch keyboard events? What are you using it for? I can't think of any scenario where this can be used. /Patric My C# blog: C# Coach

            S Offline
            S Offline
            ShimiG
            wrote on last edited by
            #5

            Im building a small program which you can get the color of any pixel on the screen, color picker after pointing on a pixel and getting its RGB and HEX into text boxes how would you remember them? just clicking on a button will get them into a list of colors :)

            1 Reply Last reply
            0
            • S ShimiG

              Thanks exactly what i was looking for ! they didnt mention that on MSDN..

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Actually, they did. Form.KeyPreview[^] RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups