Key press event

Posted by

CSharp key pressed

CSharp key pressed event shows which key is pressed which can be easily implemented through the use of events in the two text boxes. We are checking the key press events for the sake of this purpose. the code is extremely simple and small. We wish that the readers will get benefit from this program.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

// select a form application and place two textboxes over that form
namespace WindowsFormsApplication1
public partial class Form1 : Form
public Form1()

//Events attached to the key press events on two textboxes.

this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.KeyPressWork);
this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.KeyDownWork);

private void KeyDownWork(object sender, KeyEventArgs e)
MessageBox.Show(e.KeyCode.ToString(), “KeyDown”);

KeysConverter kc = new KeysConverter();
MessageBox.Show(kc.ConvertToString(e.KeyCode), “KeyDown”);

private void KeyPressWork(object sender, KeyPressEventArgs e)
MessageBox.Show(e.KeyChar.ToString(), “KeyPress”);

Facebook Comments

Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.
Syed Adeel Ahmed on FacebookSyed Adeel Ahmed on GoogleSyed Adeel Ahmed on InstagramSyed Adeel Ahmed on Twitter