mhc
mhc

Reputation: 43

How to change richTextBox's right to left type?

I wanna use a right2left language in my rich text box but faced a lot of problems with bullets etc. I want to make this

enter image description here

this is my problem enter image description here can sb help me? thanks

Upvotes: 2

Views: 3890

Answers (3)

Dmytro
Dmytro

Reputation: 17176

Just select your richtextbox and set it's RightToLeft property to Yes

enter image description here

and U will get what U need.

enter image description here

EDITS:

Then, if I understand You correctly, You should parse richtextbox's RTF yourself. Using Microsoft Word I created RTF file with left formatted and right formatted texts, compared their RTF strings and made the following:

Added openFileDialog1 control and two buttons

button1 to open file:

private void button1_Click(object sender, EventArgs e)
{
      if (openFileDialog1.ShowDialog()==DialogResult.OK)
      {
         richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText);
      }
}

and button2 to change richtextbox's RTF string:

private void button2_Click(object sender, EventArgs e)
{
     var indexofltrparObject = richTextBox1.Rtf.IndexOf(@"\ltrpar", System.StringComparison.Ordinal);
     richTextBox1.Rtf = richTextBox1.Rtf.Insert(indexofltrparObject, @"\qr");
}

So I got before button2 click:

enter image description here

and after:

enter image description here

Is that what You need?

MORE EDITS

To change text align back to LeftToRight just remove "\qr" string You have recently added to richtextbox's RTF string:

private void button3_Click(object sender, EventArgs e)
{
     int indexOfQr = richTextBox1.Rtf.IndexOf(@"\qr", System.StringComparison.Ordinal);
     if (indexOfQr != -1)
        richTextBox1.Rtf = richTextBox1.Rtf.Remove(indexOfQr, @"\qr".Length);
}

Upvotes: 3

lorenz albert
lorenz albert

Reputation: 1459

If I create an RTB I can change the style to rightToLeft. Just set this option to yes. Hope this is what you want else tell me what you want to do in detail and i may help you ;)

Edit: Maybe you can go this way. Check every line whether the first char is a bullet. If it is true Delete it and appent it to the other side.

Upvotes: 0

Talha
Talha

Reputation: 19252

change the property value of RichTextBox, RightToLeft to 'Yes'.

Upvotes: 0

Related Questions