Key Press Event In C#
-
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);
andprivate 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 --------------------- -
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);
andprivate 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 ---------------------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!
-
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);
andprivate 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 ---------------------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