Just a on the spot thought for algorithm to justify the text.
1) Find the length of your richtextbox (rtb_Length) and lengh of text (text_Length).
2)
IF text_Length > rtb_Length, Subtract the diff = rtb_Length - text_Length. [This will give you how many space is blank].
3) If you want to Justify RIGHT, then add spaces of diff value in the begining of text, else to the end of text.
Lets say text = "JustifyMyText"
So if rtb_Length = 20, text_Length = 13, then diff = 7.
FOR Justify RIGHT,
text = " JustifyMyText"
FOR Justify LEFT,
text = "JustifyMyText " OR yuo can just make text.trim() => remove all spaces.
Set the text :
richtextbox.text = text;
Hope this helps!
UPDATED SOLUTION
Try this one, I have tested and it works :
private System.Windows.Forms.RichTextBox richTextBox1;
this.richTextBox1.Location = new System.Drawing.Point(171, 13);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.richTextBox1.Size = new System.Drawing.Size(139, 53);
this.richTextBox1.TabIndex = 4;
this.richTextBox1.Text = "Rich Text Box\nJustify Left & Right\nDoes it work ?";
private void button4_Click(object sender, EventArgs e)
{
if (richTextBox1.RightToLeft == RightToLeft.No)
richTextBox1.RightToLeft = RightToLeft.Yes;
else
richTextBox1.RightToLeft = RightToLeft.No;
}
Hope this helps!