RichTextBox.SelectionIndent RichTextBox.SelectionIndent RichTextBox.SelectionIndent RichTextBox.SelectionIndent Property

定义

获取或设置所选内容开始行的缩进距离(以像素为单位)。Gets or sets the length, in pixels, of the indentation of the line where the selection starts.

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

属性值

应用到当前选定文本或插入点的左边的当前缩进距离(以像素为单位)。The current distance, in pixels, of the indentation applied to the left of the current text selection or the insertion point.

示例

下面的代码示例演示如何RichTextBox SelectionIndent使用属性在中指定缩进的文本。The following code example demonstrates how to specify indented text within the RichTextBox using the SelectionIndent property. 此示例要求RichTextBox已将名为richTextBox1的控件添加到窗体中。This example requires that a RichTextBox control, named richTextBox1, has been added to the form.

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

注解

如果当前未选择任何文本,则缩进设置将应用于插入点所在的段落以及插入点之后键入到控件中的所有文本。If no text is currently selected, the indentation setting is applied to the paragraph in which the insertion point appears and to all text that is typed into the control after the insertion point. 在将属性更改为其他值或将插入点移动到控件内的不同段落之前,缩进设置将一直生效。The indentation setting applies until the property is changed to a different value or until the insertion point is moved to a different paragraph within the control.

如果在控件中选择文本,则选定文本和在选择文本后输入的任何文本都将应用此属性的值。If text is selected within the control, the selected text and any text entered after the text selection will have the value of this property applied to it. 您可以使用此属性缩进文档RichTextBox中包含的段落。You can use this property to indent paragraphs contained in document of the RichTextBox. 可以将此属性与SelectionRightIndent一起使用,以创建在段落中显示的段落。You can use this property in conjunction with the SelectionRightIndent to create paragraphs displayed in paragraphs.

若要为控件中的段落创建悬挂缩进,请SelectionHangingIndent使用属性。To create a hanging indent for paragraphs in the control, use the SelectionHangingIndent property.

适用于

另请参阅