Control.KeyDown Problem

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.
 
D

Daisy

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();

}
 
D

Daisy

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(
 

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