我使用 RichTextBox,并且我想格式化段落中的所有行以对齐对齐,除了最后一行将对齐到中心。
像这样:
sssssssssssssssssssssssss
sssssssssssssssssssssssss
sssssssssssssssssssssssss
ssssssssssssss
我使用此代码来证明对齐。
我使用 RichTextBox,并且我想格式化段落中的所有行以对齐对齐,除了最后一行将对齐到中心。
像这样:
sssssssssssssssssssssssss
sssssssssssssssssssssssss
sssssssssssssssssssssssss
ssssssssssssss
我使用此代码来证明对齐。
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);
}
<RichTextBox>
<FlowDocument>
<Paragraph TextAlignment="Justify">
sssssssssssssssssssssssss
sssssssssssssssssssssssss
sssssssssssssssssssssssss
</Paragraph>
<Paragraph TextAlignment="Center">
sssssssssssssssssssssssss
</Paragraph>
</FlowDocument>
</RichTextBox>
主要使用段落 TextAlignment 会给你对齐文本的选项:1. 对齐,2. 居中,3. 左,4. 右;