Click here to Skip to main content
11,803,495 members (77,075 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: WPF RichTextBox
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 10:03am
Sergey Alexandrovich Kryukov at 2-Aug-12 16:16pm
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 at 2-Aug-12 16:27pm
Must be there somewere, otherwise the value on insert would be set globally, no?
Sergey Alexandrovich Kryukov at 2-Aug-12 17:10pm
...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 at 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 at 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
0 OriginalGriff 375
1 CPallini 320
2 F-ES Sitecore 270
3 Sergey Alexandrovich Kryukov 234
4 KrunalRohit 226
0 OriginalGriff 3,000
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,755
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 2 Aug 2012
Copyright © CodeProject, 1999-2015
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