OKay, quick question.
Make a windows forms app, in C#. Add a ToolStrip, in the tool strip create a textbox. Now here is the problem. Put the breakpoint on the event KeyPress or any other key event.
Run it, Press Escape key. No event is triggered.
Now the Escape key remove the focus from the textbox (you dont see the cursor inside the box). But no event is triggered for KeyChar 27 or Keys.Escpae. Why? Is this a bug?
-
-
Escape is a special key. Check out this article.
-
Escape Key is a command key, so you should achieve this with another trick, for example:
<code>
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");
}
}
}
</code>
Sheva
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.