I use a RichTextBox, and I want to format all the lines in a paragraph with justify alignment, except the last line will be aligned to the center.
as this:
sssssssssssssssssssssssss
sssssssssssssssssssssssss
sssssssssssssssssssssssss
ssssssssssssss
I use this code for justify alignment.
For instance if you want the whole textbox centered, then you would do: richTextBox1. SelectAll(); richTextBox1. SelectionAlignment = HorizontalAlignment.
The Windows Forms RichTextBox control is used for displaying, entering, and manipulating text with formatting. The RichTextBox control does everything the TextBox control does, but it can also display fonts, colors, and links; load text and embedded images from a file; and find specified characters.
What you want is "center justify". Modify the enum, it's #5 below:
/// <summary>
/// Specifies how text in a <see cref="AdvRichTextBox"/> is
/// horizontally aligned.
/// </summary>
public enum TextAlign
{
/// <summary>
/// The text is aligned to the left.
/// </summary>
Left = 1,
/// <summary>
/// The text is aligned to the right.
/// </summary>
Right = 2,
/// <summary>
/// The text is aligned in the center.
/// </summary>
Center = 3,
/// <summary>
/// The text is justified.
/// </summary>
Justify = 4,
/// <summary>
/// The text is center justified.
/// </summary>
CenterJustify = 5
}
Sample code:
private void Form1_Load(object sender, EventArgs e)
{
AdvRichTextBox tb = new AdvRichTextBox();
tb.SelectionAlignment = TextAlign.CenterJustify;
tb.SelectedText = "Here is a justified paragraph. It will show up justified using the new AdvRichTextBox control created by who knows.\n";
tb.Width = 250;
tb.Height = 450;
this.Controls.Add(tb);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With