0

I'm attempting to extend a RichTextBox in order to add some functionality, and need the ability to call a function when certain characters are entered. For instance, every time a user enters a ';', I want to call that function.

I know that I can add a OnTextChanged(object sender, TextChangedEventArgs e) method to the TextChanged event, but that doesn't seem to really solve my problem, since I can't seem to find a good way to tell what the changes were. I could check the whole document for ';' every time the text changes, but that seems to be a bit inefficient to me.

Does anyone have a better solution?

Chris Covert
  • 2,684
  • 3
  • 24
  • 31

1 Answers1

2

You should look at KeyDown Event

private void richTextBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Oem1)
    {
        DoSomething();
    }
}
Dmitrii Dovgopolyi
  • 6,231
  • 2
  • 27
  • 44