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, 5:52 AM EDT
it is for beginners not for you my dear advanced programmer sivaraman :)
Sivaraman DhamodaranTOP 100editedPosted Apr 23, 2012, 12:41 AM EDTEdited Apr 23, 2012, 12:43 AM EDT
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, 4:18 AM EST
Thnx fawad
Fawad MirzaPosted Sep 5, 2011, 11:04 AM EDT
thanks for appriciate angelina ,sumit and sam :)
Sam HobbsPosted Sep 4, 2011, 11:20 PM EDT
A more object-oriented way to do this is to derive a control from TextBox.
Sumit ShuklaPosted Sep 4, 2011, 9:18 PM EDT
Thnx it is very helpful code....
Angelina ErinPosted Sep 4, 2011, 8:03 PM EDT
Good Article.....................