gpt4 book ai didi

c# - RichTextBox 中的居中对齐段落

转载 作者:太空狗 更新时间:2023-10-29 20:37:11 25 4
gpt4 key购买 nike

我使用 RichTextBox,并且我想将段落中的所有行格式化为两端对齐,除了最后一行将居中对齐。

像这样:

      sssssssssssssssssssssssss
sssssssssssssssssssssssss
sssssssssssssssssssssssss
ssssssssssssss

我使用 this code用于证明对齐。

最佳答案

你想要的是“居中对齐”。修改枚举,它是下面的#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);
}

关于c# - RichTextBox 中的居中对齐段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11843849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com