ARTICLE

Enter Hot key on Textbox in c#

Posted by Fawad Mirza Articles | Windows Forms C# September 02, 2011
In this article, we'll look at using the Enter key to do processing
Reader Level:
Download Files:
 

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;
        }
    }
}

Login to add your contents and source code to this article
post comment
     

it is for beginners not for you my dear advanced programmer sivaraman :)

Posted by Fawad Mirza May 20, 2012

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

Posted by Sivaraman Dhamodaran Apr 23, 2012

Thnx fawad

Posted by hussein bijanpour Jan 31, 2012

thanks for appriciate angelina ,sumit and sam :)

Posted by Fawad Mirza Sep 05, 2011

A more object-oriented way to do this is to derive a control from TextBox.

Posted by Sam Hobbs Sep 05, 2011
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter