Saturday 2 May 2015

Keyboard Short cuts with in a Form - C#

Here we teach you how to make an windows form application with some keyboard short cuts that works with in that form only.
  • Open visual studio > Make a new windows form application in C# with name "form keybord shortcut" > OK
  • Then design the form as shown in the picture below.

Form Design :-





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 form_keybord_shortcut   //your project name. be care while copying.
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            listBox1.Items.Add(keyData.ToString());
            if (keyData.ToString() == "F1, Control, Alt")
                button1_Click(null, null);
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "Pressed";
        }
    }
}


Video :-






No comments:

Post a Comment