e.Handled = true doesn't work OnKeyDown

U

Udi

Hi All,
MyRichEdit is derived from RichTextBox.
I'm overriding OnKeyDown.
I'm trying to handle the TAB key but without printing it in the edit
box:

protected override bool IsInputKey(Keys keyData)
{
switch (keyData)
{
case Keys.Tab:
case Keys.Up:
case Keys.Down:
case Keys.Left:
case Keys.Right:
{
return true;
}
}
return base.IsInputKey(keyData);
}

protected override void OnKeyDown(KeyEventArgs e)
{

switch (e.KeyData)
{
case Keys.Tab:
{
e.Handled = OnTabPressed();
break;
}
:
:
}
base.OnKeyDown (e);
}


OnabPressed() returns false, but the TAB is still printed in
MyRichEdit.
What am I missing?
I'm using VS2003, XP SP1
Thanks!
 
U

Udi

As far as I know, OnKeyPressed is fired after OnKeyDown,
so it won't help since the 'TAB' will be handled OnKeyDown by the base.
Am I wrong?
 
C

Claes Bergefall

Udi said:
protected override void OnKeyDown(KeyEventArgs e)
{

switch (e.KeyData)
{
case Keys.Tab:
{
e.Handled = OnTabPressed();
break;
}
:
:
}
base.OnKeyDown (e);
}


OnabPressed() returns false, but the TAB is still printed in
MyRichEdit.

Change OnTabPressed to return true


/claes
 
T

Tom Spink

Udi said:
Hi All,
MyRichEdit is derived from RichTextBox.
I'm overriding OnKeyDown.
I'm trying to handle the TAB key but without printing it in the edit
box:
<snipeddy-doo-dah>

Hi Udi,

You need to set Handled equal to True, if you want to eat the keystroke.
 

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