use*_*998 7 c# richtextbox winforms
我使用RichTextBox,我想格式化对齐的段落中的所有行,除了最后一行将与中心对齐.
如下:
sssssssssssssssssssssssss
sssssssssssssssssssssssss
sssssssssssssssssssssssss
ssssssssssssss
Run Code Online (Sandbox Code Playgroud)
我使用此代码进行对齐.
你想要的是“居中对齐”。修改枚举,如下#5:
/// <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
}
Run Code Online (Sandbox Code Playgroud)

示例代码:
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);
}
Run Code Online (Sandbox Code Playgroud)