Control.KeyDown Problem

  • Thread starter Thread starter Jerome Terry
  • Start date Start date
J

Jerome Terry

Hi,

Why don't UserControl's received Key events for the arrow keys? Further,
when a user control is added to a Form, why does the form stop receiving Key
events for the arrow keys? I have tried setting IsInputKey(Keys.Left,
Keys.Right, Keys.Up, Keys.Down), but that doesn't work.

Regards,
Jerome.
 
Jerome Terry said:
Why don't UserControl's received Key events for the arrow keys? Further,
when a user control is added to a Form, why does the form stop receiving Key
events for the arrow keys? I have tried setting IsInputKey(Keys.Left,
Keys.Right, Keys.Up, Keys.Down), but that doesn't work.

Works for me, but my control has a scrollbar, and that also picks them up :(

See:

My code looks like:

[constructor]
this.KeyDown += new KeyEventHandler(Event_KeyDown);

[then]
public void Event_KeyDown(object sender, KeyEventArgs e)
{

// 37, 38, 39, 40, left, up, right, down
switch ((int)e.KeyCode)
{

case 37:
((Message)this.Messages[this.SelectedIndex]).Expanded = false;
break;

case 39:
((Message)this.Messages[this.SelectedIndex]).Expanded = true;
break;

case 38:
this.SelectedIndex--;
break;

case 40:
this.SelectedIndex++;
break;

}

this.Invalidate();

}
 
Jerome Terry said:
Hi,

Why don't UserControl's received Key events for the arrow keys? Further,
when a user control is added to a Form, why does the form stop receiving Key
events for the arrow keys? I have tried setting IsInputKey(Keys.Left,
Keys.Right, Keys.Up, Keys.Down), but that doesn't work.

Well, I've fixed mine, or gotten it to the same stage as you. KeyDown works
for character keys, but not cursor keys. My scrollbar seems to have stopped
stealing the focus, but I really need cursour keys to work :O(
 
Back
Top