Export (0) Print
Expand All

RichTextBox.SelectionIndent Property

Gets or sets the length, in pixels, of the indentation of the line where the selection starts.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[BrowsableAttribute(false)]
public int SelectionIndent { get; set; }

Property Value

Type: System.Int32
The current distance, in pixels, of the indentation applied to the left of the current text selection or the insertion point.

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. You can use this property to indent paragraphs contained in document of the RichTextBox. You can use this property in conjunction with the SelectionRightIndent to create paragraphs displayed in paragraphs.

To create a hanging indent for paragraphs in the control, use the SelectionHangingIndent property.

The following code example demonstrates how to specify indented text within the RichTextBox using the SelectionIndent property. 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 = 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.";
		}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft