Enter Hot key on Textbox in c#

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

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now