TextBox.IsInputKey

  • Thread starter Thread starter UdiBenSenior
  • Start date Start date
U

UdiBenSenior

Hi,

I have a class derived from richrext box that overrides IsInputKey.
I would like to handle 'Enter' in my derived class, without forwarding
it to the base (RichTextBox) - thus preventing from the base to print
the '\n'.

I tried to return false from IsInputKey but it didn't work.
What am I doing wrong?
Thanks.
 
Hi,

Frankly, I didn't spend time to find out why IsInputKey doesn't work for
RichEditBox while it should, but here is a work around that I found:

protected override bool ProcessCmdKey(ref Message m, Keys keyData)
{
if ((keyData & Keys.KeyCode) == Keys.Enter)
return true;
return base.ProcessCmdKey(ref m, keyData);
}

It uses ProcessCmdKey instead of IsInputKey (the latter by the way I believe
is the correct place to put your code, but apparently it doesn't work). The
code blocks any combination of modifier keys and Enter that is Ctrl+Enter,
Shif+Enter, etc will be all blocked. If you want to allow some of the
combination you should change the condition.
 
Back
Top