Problem with RichTextBox SelectedRtf
-
I'm having difficulty adding hidden text to a RichTextBox. See case2 below. Case1: Initialize Form1 in Main(string[] args){}. In Form1, initialize a RichTextBox as follows: RichTextBox rtb = new RichTextBox(); Observe that rtb.SelectedRtf is initially set to "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n"; Now try: rtb.SelectedRtf = @"{\rtf1\ansi " + "visibleText" + @"\v " + "hiddenText" + @"\v0}"; result: rtb.Text = "visibleTexthiddenText" as expected. Case2: Form1 is initialized as an MDIChild Form: Again in Form1, initialize a RichTextBox as follows: RichTextBox rtb = new RichTextBox(); This time rtb.SelectedRtf is initially set to empty string. Try: rtb.SelectedRtf = @"{\rtf1\ansi " + "visibleText" + @"\v " + "hiddenText" + @"\v0}"; result: rtb.Text = "visibleText" i.e. the hidden text is not being updated when Form1 is an MDIChild. Anyone know the cause/walkaround? Your help is appreciated. Thanks, B
-
I'm having difficulty adding hidden text to a RichTextBox. See case2 below. Case1: Initialize Form1 in Main(string[] args){}. In Form1, initialize a RichTextBox as follows: RichTextBox rtb = new RichTextBox(); Observe that rtb.SelectedRtf is initially set to "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n"; Now try: rtb.SelectedRtf = @"{\rtf1\ansi " + "visibleText" + @"\v " + "hiddenText" + @"\v0}"; result: rtb.Text = "visibleTexthiddenText" as expected. Case2: Form1 is initialized as an MDIChild Form: Again in Form1, initialize a RichTextBox as follows: RichTextBox rtb = new RichTextBox(); This time rtb.SelectedRtf is initially set to empty string. Try: rtb.SelectedRtf = @"{\rtf1\ansi " + "visibleText" + @"\v " + "hiddenText" + @"\v0}"; result: rtb.Text = "visibleText" i.e. the hidden text is not being updated when Form1 is an MDIChild. Anyone know the cause/walkaround? Your help is appreciated. Thanks, B
-
I am facing the same issue. Its been 5 years since you have asked this question. Did you get the solution ? If so, please share with me.
-
As I recall an external component was loading a different version of the riched32.dll/riched20dll. Workaround was to initialize the right dll first (new RichTextBox() in your application). Hope this helps.