C# KeyChar, KeyCode

How To Use Key Char And Key Code In C#

C# Key Char & Key Code


In This C# Tutorial  We Will See How To Use KeyChar And KeyCode To Check Which Key Is Pressed ENTER or SPACE, SHIFT... In CSharp Programming Language And Visual  Studio Editor.


Project 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.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Csharp_keycode_keychar : Form
    {
        public Csharp_keycode_keychar()
        {
            InitializeComponent();
        }

// keycode
        private void Csharp_keycode_keychar_KeyDown(object sender, KeyEventArgs e)
        {

            if ((e.KeyCode == Keys.Enter) && e.Control)
                label1.Text = "CONTROL + ENTER";
            else
                label1.Text = "/////";

        }

// keychar
        private void Csharp_keycode_keychar_KeyPress(object sender, KeyPressEventArgs e)
        {
            
            if(e.KeyChar == (char)Keys.Space)
                label1.Text = "spacebar";
            else
                label1.Text = "/////";
           
        }
    }
}



// OUTPUT :

c# enter key keychar




Share this

Related Posts

Previous
Next Post »