如何:在 Windows 窗体 RichTextBox 控件中设置缩进、悬挂缩进和带项目符号的段落

更新:2007 年 11 月

Windows 窗体 RichTextBox 控件具有多个用于设置所显示的文本的格式的选项。可以通过设置 SelectionBullet 属性将选定的段落设置为项目符号列表的格式。也可以使用 SelectionIndentSelectionRightIndentSelectionHangingIndent 属性设置段落相对于控件的左右边缘以及其他文本行的左边缘进行缩进。

将段落设置为项目符号列表格式

  • SelectionBullet 属性设置为 true。

    RichTextBox1.SelectionBullet = True
    
    richTextBox1.SelectionBullet = true;
    
    richTextBox1->SelectionBullet = true;
    

缩进段落

  1. SelectionIndent 属性设置为一个整数,该整数表示控件的左边缘和文本的左边缘之间的距离(以像素为单位)。

  2. SelectionHangingIndent 属性设置为一个整数,该整数表示段落中第一行文本的左边缘与同一段落中后面的行的左边缘之间的距离(以像素为单位)。SelectionHangingIndent 属性的值只适用于段落换行后第一行下面的行。

  3. SelectionRightIndent 属性设置为一个整数,该整数表示控件的右边缘与文本的右边缘之间的距离(以像素为单位)。

    RichTextBox1.SelectionIndent = 8
    RichTextBox1.SelectionHangingIndent = 3
    RichTextBox1.SelectionRightIndent = 12
    
    richTextBox1.SelectionIndent = 8;
    richTextBox1.SelectionHangingIndent = 3;
    richTextBox1.SelectionRightIndent = 12;
    
    richTextBox1->SelectionIndent = 8;
    richTextBox1->SelectionHangingIndent = 3;
    richTextBox1->SelectionRightIndent = 12;
    
    说明:

    所有上述属性均会影响包含选定文本的所有段落,还会影响在当前插入点之后键入的文本。例如,当用户在段落中选择一个词然后调整缩进时,则新设置将应用于包含这个词的整个段落,还会应用于在选定的段落之后输入的任何段落。有关以编程方式选择文本的更多信息,请参见 TextBoxBase.Select 方法

请参见

参考

RichTextBox

其他资源

RichTextBox 控件(Windows 窗体)

在 Windows 窗体上使用的控件