Answered by:
displaying issue when switching between RTL and LTR in Win Form Rich Text Box

Question
-
I tried the same thing in both Win form and WPF form and seems this only happens in Win Form. Basically what's happening is that I have a RTB control in Win Form, and 2 buttons: RTL and LTR to adjust the alignment.
button1 clicked:
richTextBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
button2 clicked:
richTextBox1.RightToLeft = System.Windows.Forms.RightToLeft.No;
That's all I have. when I paste text into RTB and click on the RTL button, it left a big gap in RTB. I noticed this will ONLY happen if the scroll bar is presenting. if you resize the form, the gap will go away.
I tried everything I could but couldn't figure out why it's happening. I suspect it's a .NET bug, does anybody have any idea?
Friday, November 14, 2014 4:23 PM
Answers
-
Try this workaround:
string text = richTextBox1.Text; richTextBox1.Clear(); richTextBox1.RightToLeft = RightToLeft.Yes; BeginInvoke( new Action( () => richTextBox1.Text = text ) );
Note that the formatting (fonts, colours) are not preserved when RightToLeft is changed at run-time (according to Documentation).
- Marked as answer by Carl Cai Tuesday, November 25, 2014 12:02 PM
Saturday, November 15, 2014 6:06 PM -
Hi youkebb,
I have made a test about what you put forward, the reply from Viorel might be useful to you. Also,
You could also try the code below:
string txtRTF = richTextBox1.Rtf; richTextBox1.Clear(); richTextBox1.RightToLeft=System.Windows.Forms.RightToLeft.Yes; Application.DoEvents(); richTextBox1.Rtf = txtRTF;
If you have any further questions, please feel free to post in this forum.
Best regards,
LeoTuesday, November 18, 2014 10:03 AM
All replies
-
Try this workaround:
string text = richTextBox1.Text; richTextBox1.Clear(); richTextBox1.RightToLeft = RightToLeft.Yes; BeginInvoke( new Action( () => richTextBox1.Text = text ) );
Note that the formatting (fonts, colours) are not preserved when RightToLeft is changed at run-time (according to Documentation).
- Marked as answer by Carl Cai Tuesday, November 25, 2014 12:02 PM
Saturday, November 15, 2014 6:06 PM -
Hi youkebb,
I have made a test about what you put forward, the reply from Viorel might be useful to you. Also,
You could also try the code below:
string txtRTF = richTextBox1.Rtf; richTextBox1.Clear(); richTextBox1.RightToLeft=System.Windows.Forms.RightToLeft.Yes; Application.DoEvents(); richTextBox1.Rtf = txtRTF;
If you have any further questions, please feel free to post in this forum.
Best regards,
LeoTuesday, November 18, 2014 10:03 AM