Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to be able to determine if insert mode is active in a WPF RichTextBox. I tried using reflection like so:

C#
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
Comments
Sergey Alexandrovich Kryukov 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.
--SA
Kenneth Haugland 2-Aug-12 16:27pm    
Must be there somewere, otherwise the value on insert would be set globally, no?
Sergey Alexandrovich Kryukov 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...
--SA
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

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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900