Click here to Skip to main content
13,407,694 members (52,280 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I need to be able to determine if insert mode is active in a WPF RichTextBox. I tried using reflection like so:

PropertyInfo pInfo = this.GetType().GetProperty("_OvertypeMode", BindingFlags.NonPublic | BindingFlags.Instance);

However, the property _OverTypeMode doesn't exist in the RichTextBox that I could find.

Does anyone know how to do this?

Google was no help.
Posted 2-Aug-12 11:03am
How do you know it's supposed to exist? Apparently, there is no access to insert/overwrite switch... have no idea how to achieve that.
Kenneth Haugland 2-Aug-12 16:27pm
Must be there somewere, otherwise the value on insert would be set globally, no?
...already forgot how it works... In some editors, Insert key is ignored (and I like it), in some it is not... I just tested CMD vs my editor based on native Windows RichEdit control -- they are independent. But maybe you are right in your last statement, below...
Kenneth Haugland 2-Aug-12 17:27pm
Perhaps you could ovverride the Insert function by stopping the text addition/insert in the Preview Text input?
Sorry, didnt see that he ha solved it...
Kenneth Haugland 2-Aug-12 16:31pm
THe value could be found by Keyboard.IsKeyToggled(Key.Insert) and you assume that this is stored somewere in the RTB. At least it seems that IsKeyToggeled applies to all text elements in WPF, and sould perhaps stem from TextBoxBase control, whitch RTB implements.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I found out that in WPF, a TextBox or RichTextBox always defaults to Insert being ON when the control is instantiated. With that knowledge, I simply track the pressing of Key.Insert, and maintain my own variable that indicates status.

Problem solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01-2016 | 2.8.180212.1 | Last Updated 2 Aug 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100