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. Winform KeyPress

Winform KeyPress

Scheduled Pinned Locked Moved C#
questiondatabasehelp
7 Posts 4 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I ran into this before and just did a work around so no biggy. However this is now the second time this has occurred and I dug a little bit and it does nto makes sence. Maybe I am doing something wrong. So I have an empty WinForm... Abosultely nothing in it. I create a KeyPress event trigger. (in this case I want 4 which is -d). Everything works. I add a control (any control... even a button) and my event no longer fires. Why does it not fire, and is there an easy way to fix it? Thank you,

    M D T 3 Replies Last reply
    0
    • L Lost User

      I ran into this before and just did a work around so no biggy. However this is now the second time this has occurred and I dug a little bit and it does nto makes sence. Maybe I am doing something wrong. So I have an empty WinForm... Abosultely nothing in it. I create a KeyPress event trigger. (in this case I want 4 which is -d). Everything works. I add a control (any control... even a button) and my event no longer fires. Why does it not fire, and is there an easy way to fix it? Thank you,

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      The keypress event will only be triggered if the form has focus. if you want other controls to perform the same function then you must use there keypress events too.

      Life goes very fast. Tomorrow, today is already yesterday.

      D 1 Reply Last reply
      0
      • L Lost User

        I ran into this before and just did a work around so no biggy. However this is now the second time this has occurred and I dug a little bit and it does nto makes sence. Maybe I am doing something wrong. So I have an empty WinForm... Abosultely nothing in it. I create a KeyPress event trigger. (in this case I want 4 which is -d). Everything works. I add a control (any control... even a button) and my event no longer fires. Why does it not fire, and is there an easy way to fix it? Thank you,

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

        The form has a KeyPreview property. Set that to true and you form Key handlers will get first crack at the keystrokes before any controls on it do.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        L 1 Reply Last reply
        0
        • M musefan

          The keypress event will only be triggered if the form has focus. if you want other controls to perform the same function then you must use there keypress events too.

          Life goes very fast. Tomorrow, today is already yesterday.

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

          And if you have some 30 controls on a form?? Your solution doesn't sound like a good method to me.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            And if you have some 30 controls on a form?? Your solution doesn't sound like a good method to me.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            Yeah I see your point, I was thou more concerned on saying why it wasn't working rather than giving a solution, yet one made its way in :) Thou I suppose it depends on the usage, perhaps two different text boxes need to do two different things when the 'Enter' key is pressed. Sure you can check focus on the form's preview event, but then what if you want to process a textbox after input, to validate its contents for example (although I already thought you can calculate new value from key press) anyway, is circumstantial, that' all i'm saying ;)

            Life goes very fast. Tomorrow, today is already yesterday.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              The form has a KeyPreview property. Set that to true and you form Key handlers will get first crack at the keystrokes before any controls on it do.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Sweet! Thank you!

              1 Reply Last reply
              0
              • L Lost User

                I ran into this before and just did a work around so no biggy. However this is now the second time this has occurred and I dug a little bit and it does nto makes sence. Maybe I am doing something wrong. So I have an empty WinForm... Abosultely nothing in it. I create a KeyPress event trigger. (in this case I want 4 which is -d). Everything works. I add a control (any control... even a button) and my event no longer fires. Why does it not fire, and is there an easy way to fix it? Thank you,

                T Offline
                T Offline
                terradtc
                wrote on last edited by
                #7

                Sounds like you're trying to create an accellerator, have a look at this: http://www.codeguru.com/columns/experts/article.php/c4639[^]

                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