RichTextBox中的中心对齐段落

时间:2012-08-07 10:21:06

标签: c# winforms richtextbox

我使用RichTextBox,并且我希望使用对齐方式格式化段落中的所有行,除了最后一行将与中心对齐。

这样:

      sssssssssssssssssssssssss
      sssssssssssssssssssssssss
      sssssssssssssssssssssssss
           ssssssssssssss     

我使用this code来证明对齐。

2 个答案:

答案 0 :(得分:2)

你想要的是“中心辩护”。修改枚举,下面是#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
}

enter image description here

示例代码:

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);
}

答案 1 :(得分:0)

<RichTextBox>
            <FlowDocument>
                <Paragraph TextAlignment="Justify">
                    sssssssssssssssssssssssss
                    sssssssssssssssssssssssss
                    sssssssssssssssssssssssss
                </Paragraph>
                <Paragraph TextAlignment="Center">
                    sssssssssssssssssssssssss
                </Paragraph>
            </FlowDocument>
</RichTextBox>

主要使用段落TextAlignment将为您提供对齐文本的选项:1。对齐,2。居中,3。左,4。右;