Catching Keys.Left on KeyDown for Button Control

M

matt.b.williams

I am in a situation where I need to catch the key press of the Left
directional key while the focus is on a button. I have added the
KeyDown event handler, but the directional keys are not caught by this
event. This is in Windows CE 4.2 and the coding is done in Visual
Studio.NET 2003 so there is no KeyPreview property for the form on
which this button resides. I have attempted to override the OnKeyDown
event, but for some reason, it never enters into the override code.

If anyone could provide me with some assistance, and better yet, some
sample code, it would be very much appreciated.

Thanks in advance for any help.

Matt
 
R

Russ Du Preez

Hi Matt,

Hope this will help you:

private void Form1_Load(object sender, System.EventArgs e)
{
button1.KeyDown +=new KeyEventHandler(button1_KeyDown);
button1.Focus();
}

private void button1_KeyDown(object sender, KeyEventArgs e)
{
if((e.KeyData == Keys.Down) || (e.KeyData == Keys.Left))
{
MessageBox.Show(e.KeyData.ToString() + " Key event caught!!");
}
}


Thanks,
Russ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top