RichTextBox.SelectionIndent 属性

定义

获取或设置所选内容开始行的缩进距离(以像素为单位)。

public:
 property int SelectionIndent { int get(); void set(int value); };
[System.ComponentModel.Browsable(false)]
public int SelectionIndent { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionIndent : int with get, set
Public Property SelectionIndent As Integer

属性值

应用到当前选定文本或插入点的左边的当前缩进距离(以像素为单位)。

属性

示例

下面的代码示例演示如何使用 SelectionIndent 属性在 中RichTextBox指定缩进文本。 此示例要求 RichTextBox 已将名为 richTextBox1的控件添加到窗体中。

private:
   void WriteIndentedTextToRichTextBox()
   {
      // Clear all text from the RichTextBox;
      richTextBox1->Clear();

      // Specify a 20 pixel indent in all paragraphs.
      richTextBox1->SelectionIndent = 20;

      // Set the font for the text.
      richTextBox1->Font = gcnew System::Drawing::Font( "Lucinda Console",12 );

      // Set the text within the control.
      richTextBox1->SelectedText = "All text is indented 20 pixels from the left edge of the RichTextBox.";
      richTextBox1->SelectedText = "You can use this property to provide proper indentation such as when writing a letter.";
      richTextBox1->SelectedText = "After this paragraph the indent is returned to normal spacing.\n\n";
      richTextBox1->SelectionIndent = 0;
      richTextBox1->SelectedText = "No indenation is applied to this paragraph. All text in the paragraph flows from each control edge.";
   }
private void WriteIndentedTextToRichTextBox()
{
    // Clear all text from the RichTextBox;
    richTextBox1.Clear();
    // Specify a 20 pixel indent in all paragraphs.
    richTextBox1.SelectionIndent = 20;
    // Set the font for the text.
    richTextBox1.Font = new Font("Lucinda Console", 12);
    // Set the text within the control.
    richTextBox1.SelectedText = "All text is indented 20 pixels from the left edge of the RichTextBox.";
    richTextBox1.SelectedText = "You can use this property to provide proper indentation such as when writing a letter.";
    richTextBox1.SelectedText = "After this paragraph the indent is returned to normal spacing.\n\n";
    richTextBox1.SelectionIndent = 0;
    richTextBox1.SelectedText = "No indenation is applied to this paragraph. All text in the paragraph flows from each control edge.";
}
Private Sub WriteIndentedTextToRichTextBox()
   ' Clear all text from the RichTextBox;
   RichTextBox1.Clear()
   ' Set the font for the text.
   RichTextBox1.Font = New Font("Lucinda Console", 12)
   ' Specify a 20 pixel indent in all paragraphs.
   RichTextBox1.SelectionIndent = 20
   ' Set the text within the control.
   RichTextBox1.SelectedText = "All text is indented 20 pixels from the left edge of the RichTextBox."
   RichTextBox1.SelectedText = "You can use this property to provide proper indentation such as when writing a letter."
   RichTextBox1.SelectedText = "After this paragraph the indent is returned to normal spacing." + ControlChars.Crlf
   RichTextBox1.SelectionIndent = 0
   RichTextBox1.SelectedText = "No indenation is applied to this paragraph. All text in the paragraph flows from each control edge."
End Sub

注解

如果当前未选择任何文本,缩进设置将应用于显示插入点的段落,以及插入点后键入控件的所有文本。 缩进设置将一直应用,直到属性更改为其他值,或者直到插入点移动到控件中的其他段落为止。

如果在控件中选择了文本,则所选文本和在文本选择后输入的任何文本都将应用此属性的值。 可以使用此属性缩进 文档 RichTextBox中包含的段落。 可以将此属性与 SelectionRightIndent 结合使用,以创建在段落中显示的段落。

若要为控件中的段落创建悬挂缩进,请使用 SelectionHangingIndent 属性。

适用于

另请参阅