I have just found out that we can't use the KeyDown
event directly with a PictureBox
. So I have to change my strategy.
I decided to add the Keydown
event to the actual form:
private void FullColourPaletteForm_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Left:
{
MessageBox.Show("Left");
e.Handled = true;
return;
}
}
}
Doesn't get executed. I see no message box when I press the left allow. Instead (and rightly so) it just moves the cusor from control to control.
I was hoping to be able to mimic some kind of cursor support for the block of colour by intercepting the arrow keys inside the picture box.
I am not sure of the best way forward. I don't want to break the standard dialogue functionality of moving between controls, but I want to now include suipport for detectign keys so I can add my code to move my block of colour.
Can it be done? Not sure why my event is not getting triggered in the form anyway.
I saw this question. So I tried setting my form KeyPreview property. No joy. I also looked at ProcessCmdKey
but it doesn't seem right for the issue in hand.
Update:
If I try to follow the idea in the comments and create a SelectablePictureBox control, it looks like this:
I have two issues. 1. I still can't seem to work out how to handle the keydown event on my pictureBox object itself. I am reluctant to manually add any handlers to the designer file incase my changes get lost.
Also, when doing general control nagivation on the form with cursor keys it does not seem to know about this control.