7

我使用 RichTextBox,并且我想格式化段落中的所有行以对齐对齐,除了最后一行将对齐到中心。

像这样:

      sssssssssssssssssssssssss
      sssssssssssssssssssssssss
      sssssssssssssssssssssssss
           ssssssssssssss     

我使用此代码来证明对齐。

4

2 回答 2

3

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
}

enter image description here

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);
}
于 2012-08-07T12:02:44.913 回答
0
<RichTextBox>
            <FlowDocument>
                <Paragraph TextAlignment="Justify">
                    sssssssssssssssssssssssss
                    sssssssssssssssssssssssss
                    sssssssssssssssssssssssss
                </Paragraph>
                <Paragraph TextAlignment="Center">
                    sssssssssssssssssssssssss
                </Paragraph>
            </FlowDocument>
</RichTextBox>

主要使用段落 TextAlignment 会给你对齐文本的选项:1. 对齐,2. 居中,3. 左,4. 右;

于 2018-05-22T11:48:15.350 回答