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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. keyup/keypress event for forms

keyup/keypress event for forms

Scheduled Pinned Locked Moved C#
tutorialquestion
3 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.
  • J Offline
    J Offline
    jeweladdict
    wrote on last edited by
    #1

    How would i go about assigning the F12 key to focus on a textbox within a form? Meaning when a form is active, if the f12 key is pressed (doesn't matter which component is active) the focus will be set to a certain textbox. I know how to set the event when a certain component is active, but if i want to set a global keyup event, how would i do so? Here is the code for a textbox keyup: this.textBox_units.KeyUp += new System.Windows.Forms.KeyEventHandler this.textBox_units_EnterKeyPressed); private void textBox_units_EnterKeyPressed(object sender, System.Windows.Forms.KeyEventArgs e ) { if(( e.KeyCode == Keys.Enter ) || ( e.KeyCode == Keys.Return )) { this.textBox_upc.Focus(); } }

    S 1 Reply Last reply
    0
    • J jeweladdict

      How would i go about assigning the F12 key to focus on a textbox within a form? Meaning when a form is active, if the f12 key is pressed (doesn't matter which component is active) the focus will be set to a certain textbox. I know how to set the event when a certain component is active, but if i want to set a global keyup event, how would i do so? Here is the code for a textbox keyup: this.textBox_units.KeyUp += new System.Windows.Forms.KeyEventHandler this.textBox_units_EnterKeyPressed); private void textBox_units_EnterKeyPressed(object sender, System.Windows.Forms.KeyEventArgs e ) { if(( e.KeyCode == Keys.Enter ) || ( e.KeyCode == Keys.Return )) { this.textBox_upc.Focus(); } }

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

      Register to the KeyUp event of your form and set its KeyPreview property true.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      J 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Register to the KeyUp event of your form and set its KeyPreview property true.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        J Offline
        J Offline
        jeweladdict
        wrote on last edited by
        #3

        works like a charm thanks :D

        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