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. Key Press Event In C#

Key Press Event In C#

Scheduled Pinned Locked Moved C#
csharpcomhelp
3 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
    Areff
    wrote on last edited by
    #1

    Hi, I want 2 use KeyEventHandler in a form but when i use this statement no event happen this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress); and private void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { Lbl1.Text = ((System.Windows.Forms.Key) Sender).ToString(); } plz help me. --------------------- Areff Bahrami(KAVEH) Areff.HB@Gmail.com ---------------------

    J G 2 Replies Last reply
    0
    • A Areff

      Hi, I want 2 use KeyEventHandler in a form but when i use this statement no event happen this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress); and private void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { Lbl1.Text = ((System.Windows.Forms.Key) Sender).ToString(); } plz help me. --------------------- Areff Bahrami(KAVEH) Areff.HB@Gmail.com ---------------------

      J Offline
      J Offline
      Jakob Farian Krarup
      wrote on last edited by
      #2

      Have you tried setting the form's KeyPreview property to true? Kind regards - Jakob Three kinds of people in the world: - Those who can count.. - Those who can't!

      1 Reply Last reply
      0
      • A Areff

        Hi, I want 2 use KeyEventHandler in a form but when i use this statement no event happen this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress); and private void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { Lbl1.Text = ((System.Windows.Forms.Key) Sender).ToString(); } plz help me. --------------------- Areff Bahrami(KAVEH) Areff.HB@Gmail.com ---------------------

        G Offline
        G Offline
        Graham Nimbley
        wrote on last edited by
        #3

        I think you may have confused what is passed in through 'sender'. In this situation sender returns a reference to the control which received the key press. If you want to access the key which was sent, you can use e.KeyChar Graham

        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