In my project there is a Form mainForm in which there are two textBoxes txtUserName and txtPassword and also a button btnLogin>
mainForm
txtUserName
txtPassword
btnLogin>
You need to override the keydown event handler.
protected override void OnKeyDown(KeyEventArgs e) { //call original event handler. Remove it if you don't need it at all. base.OnKeyDown(e); //Insert your code here.... }