Intercepting characters

  • Thread starter Thread starter Einar Høst
  • Start date Start date
E

Einar Høst

Hi,

I'm a newbie in GUI programming, so please bear over with me.

I'm using a RichTextBox, but I would like to restrict the set of legal
characters to, say, digits only. I got the idea that I should subclass
RichTextBox and prevent some event from reaching the base class, but I don't
know which event to intercept, or if that's the correct way to do it. Any
help would be much appreciated!
 
Einar Høst said:
I'm using a RichTextBox, but I would like to restrict the set of legal
characters to, say, digits only.

RichTextBox derives from Control, therefore all that's required is
overriding the OnKeyDown, OnKeyPress and OnKeyUp methods.

When e.KeyCode is between 48 and 57 (inclusive) or 96 and 105
(inclusive; for digits entered via the numeric keypad), call the base
class' OnKeyDown, etc. For any other values you want to filter out,
do NOT call the base class' methods.


Derek Harmon
 
Back
Top