RichTextBox.SelectionIndent 属性

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property SelectionIndent As Integer
用法
Dim instance As RichTextBox
Dim value As Integer

value = instance.SelectionIndent

instance.SelectionIndent = value
public int SelectionIndent { get; set; }
public:
property int SelectionIndent {
    int get ();
    void set (int value);
}
/** @property */
public int get_SelectionIndent ()

/** @property */
public void set_SelectionIndent (int value)
public function get SelectionIndent () : int

public function set SelectionIndent (value : int)

属性值

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

备注

如果当前未选定任何文本,则缩进设置应用到插入点所在段落和在此插入点后键入到控件中的所有文本。缩进设置一直应用到此属性更改为其他值或插入点移动到控件内的其他段落为止。

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

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

示例

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

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
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:
   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.set_SelectionIndent(20);
    // Set the font for the text.
    richTextBox1.set_Font(new Font("Lucinda Console", 12));
    // Set the text within the control.
    richTextBox1.set_SelectedText("All text is indented 20 pixels from the"
        + "left edge of the RichTextBox.");
    richTextBox1.set_SelectedText("You can use this property to provide "
        + "proper indentation such as when writing a letter.");
    richTextBox1.set_SelectedText("After this paragraph the indent is "
        + "returned to normal spacing.\n\n");
    richTextBox1.set_SelectionIndent(0);
    richTextBox1.set_SelectedText("No indenation is applied to this paragraph."
        + "All text in the paragraph flows from each control edge.");
} //WriteIndentedTextToRichTextBox

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

RichTextBox 类
RichTextBox 成员
System.Windows.Forms 命名空间
SelectionRightIndent
RichTextBox.SelectionHangingIndent 属性