Wednesday, August 11, 2010

Handling the ESC Key in C#

Found this here: http://channel9.msdn.com/forums/TechOff/224745-Escape-Key-Event-Bug-C/?CommentID=224767
Escape Key is a command key, so you should achieve this with another trick, for example:

using System;
using System.Windows.Forms;

namespace HandleEscapeKeyDemo
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        protected override Boolean ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                OnPressEscapeKey();
            }
            return true;
        }

        private void OnPressEscapeKey()
        {
            MessageBox.Show("Escape Key Is Pressed");
        }
    }
}


Sheva

WORKS!

No comments:

Post a Comment