I've set KeyPreview = true;
for my Form
. I basically want to use the arrow keys to go to the next and previous images instead of changing focus to different controls. I've set the Handled
property to true
but still the focus changes on arrow key press.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
// Do stuff
}
else if (e.KeyCode == Keys.Left)
{
// Do stuff
e.Handled = true;
}
else if (e.KeyCode == Keys.Right)
{
// Do stuff
e.Handled = true;
}
}
EDIT
The behavior I want to achieve is as follows.
Left Arrow Key -> Previous Image
Right Arrow Key -> Next Image
Now, I also have a few TextBox
es on my Form
and I therefore do not want to go to next and previous images if those Textbox
es are in focus because then it should navigate through the text instead.