HOW TO MAKE 'ENTER' HOTKEY CONTROL ON TEXTBOX IN C#
First click on the textbox and then go to the properties and in the event section double click on the "keydown event".
After, select the keydown event and write the code in.
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
textBox2.Select();
textBox2.BackColor = Color.SkyBlue;
textBox1.BackColor = Color.Empty;
}
}
Source code:
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;
namespace WindowsFormsApplication44
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
textBox2.Select();
textBox2.BackColor = Color.SkyBlue;
textBox1.BackColor = Color.Empty;
}
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
textBox3.Select();
textBox3.BackColor = Color.SkyBlue;
textBox2.BackColor = Color.Empty;
}
}
private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
textBox4.Select();
textBox4.BackColor = Color.SkyBlue;
textBox3.BackColor = Color.Empty;
}
}
private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
textBox1.Select();
textBox1.BackColor = Color.SkyBlue;
textBox4.BackColor = Color.Empty;
}
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Select();
textBox1.BackColor = Color.SkyBlue;
}
}
}

Fawad MirzaPosted May 20, 2012, 9:52 AM
it is for beginners not for you my dear advanced programmer sivaraman :)
Sivaraman DhamodaraneditedPosted Apr 23, 2012, 4:41 AMEdited Apr 23, 2012, 4:43 AM
Submitted some piece of code. Where is the article? I would say this is just a junk in the name of article. I hope the site is strict now and won't allow this kind of thing as article
hussein bijanpourPosted Jan 31, 2012, 9:18 AM
Thnx fawad
Fawad MirzaPosted Sep 5, 2011, 3:04 PM
thanks for appriciate angelina ,sumit and sam :)
Sam HobbsPosted Sep 5, 2011, 3:20 AM
A more object-oriented way to do this is to derive a control from TextBox.
Sumit ShuklaPosted Sep 5, 2011, 1:18 AM
Thnx it is very helpful code....
Angelina ErinPosted Sep 5, 2011, 12:03 AM
Good Article.....................