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. Event issue

Event issue

Scheduled Pinned Locked Moved C#
help
4 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.
  • A Offline
    A Offline
    atulonweb hotmail com
    wrote on last edited by
    #1

    Hi If there is not any button control on winform then forms key press event is fires But if we place button control on winform then focus directly goes to button and keypress event of the form does not get fired.What can be the reason. It can be easily replicated by just writing any code in keypress event of windows form there should not be any control on the form then its keypress will be fired, now just place a button control u will see form's key pressed is not getting fired. It seems focus issue.Can anyone advice. Atul Kumar

    M J 2 Replies Last reply
    0
    • A atulonweb hotmail com

      Hi If there is not any button control on winform then forms key press event is fires But if we place button control on winform then focus directly goes to button and keypress event of the form does not get fired.What can be the reason. It can be easily replicated by just writing any code in keypress event of windows form there should not be any control on the form then its keypress will be fired, now just place a button control u will see form's key pressed is not getting fired. It seems focus issue.Can anyone advice. Atul Kumar

      M Offline
      M Offline
      MCSD Gandalf
      wrote on last edited by
      #2

      In Windows applications, if there is ANY control on a form that CAN receive the focus it does, and the form does not. You are correct, it is a focus issue, and it was designed that way. HTH explain it anyway. ;)

      1 Reply Last reply
      0
      • A atulonweb hotmail com

        Hi If there is not any button control on winform then forms key press event is fires But if we place button control on winform then focus directly goes to button and keypress event of the form does not get fired.What can be the reason. It can be easily replicated by just writing any code in keypress event of windows form there should not be any control on the form then its keypress will be fired, now just place a button control u will see form's key pressed is not getting fired. It seems focus issue.Can anyone advice. Atul Kumar

        J Offline
        J Offline
        Josh Smith
        wrote on last edited by
        #3

        Set the Form's KeyPreview property to true, and it's KeyPress event will fire before the active control's KeyPress. Josh

        A 1 Reply Last reply
        0
        • J Josh Smith

          Set the Form's KeyPreview property to true, and it's KeyPress event will fire before the active control's KeyPress. Josh

          A Offline
          A Offline
          atulonweb hotmail com
          wrote on last edited by
          #4

          Thanx a LOT Josh It is working.

          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