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

KeyPress ....

Scheduled Pinned Locked Moved C#
debugginghelpquestion
2 Posts 2 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.
  • M Offline
    M Offline
    mitreviper
    wrote on last edited by
    #1

    Hi all, I'm trying to respond to the letter 'a' being pressed . But some how when i ran the form, this KeyPress function was not activated at all. Is there something else I need to do ? I have this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.frmMain_KeyPress); inserted automatically already. Please help. Does this mean that the form is no focus??? I already clicked on the form and tried typing 'a' but no messagebox shown or was did debug mode enter the source code. private void frmMain_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { switch ( e.KeyChar) { case 'a': MessageBox.Show("a"); break; } }

    S 1 Reply Last reply
    0
    • M mitreviper

      Hi all, I'm trying to respond to the letter 'a' being pressed . But some how when i ran the form, this KeyPress function was not activated at all. Is there something else I need to do ? I have this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.frmMain_KeyPress); inserted automatically already. Please help. Does this mean that the form is no focus??? I already clicked on the form and tried typing 'a' but no messagebox shown or was did debug mode enter the source code. private void frmMain_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { switch ( e.KeyChar) { case 'a': MessageBox.Show("a"); break; } }

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Normally a form automatically receives all keyboard events, if it has no visible or enabled controls. But if it has controls, I think the focus is never on the form itself but always on a contained control. Try setting the KeyPreview property of your form to true, so your form receives key events before the event is passed to the control that has focus.


      www.troschuetz.de

      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