This documentation is archived and is not being maintained.

RichTextBox.SelectionHangingIndent Property

Gets or sets the distance between the left edge of the first line of text in the selected paragraph and the left edge of subsequent lines in the same paragraph.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public int SelectionHangingIndent { get; set; }
/** @property */
public int get_SelectionHangingIndent ()

/** @property */
public void set_SelectionHangingIndent (int value)

public function get SelectionHangingIndent () : int

public function set SelectionHangingIndent (value : int)

Not applicable.

Property Value

The distance, in pixels, for the hanging indent applied to the current text selection or the insertion point.

If no text is currently selected, the hanging indent 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 hanging indent 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 apply a hanging indent to your paragraphs.

To set the indention of the first line of a paragraph selection, use the SelectionIndent property.

The following code example demonstrates how to specify hanging indents within the RichTextBox using the SelectionHangingIndent 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 hanging indent in all paragraphs.
   richTextBox1.SelectionHangingIndent = 20;
   // Set the font for the text.
   richTextBox1.Font = new Font("Lucinda Console", 12);
   // Set the text within the control.
   richTextBox1.SelectedText = "This text contains a hanging indent. The first sentence of the paragraph is spaced normally.";
   richTextBox1.SelectedText = "All subsequent lines of text are indented based on the value of SelectionHangingIndent.";
   richTextBox1.SelectedText = "After this paragraph the indent is returned to normal spacing.\n";
   richTextBox1.SelectedText = "Since this is a new paragraph the indent is also applied to this paragraph.";
   richTextBox1.SelectedText = "All subsequent lines of text are indented based on the value of SelectionHangingIndent.";
}

private void WriteIndentedTextToRichTextBox()
{
    // Clear all text from the RichTextBox;
    richTextBox1.Clear();
    // Specify a 20 pixel hanging indent in all paragraphs.
    richTextBox1.set_SelectionHangingIndent(20);
    // Set the font for the text.
    richTextBox1.set_Font(new Font("Lucinda Console", 12));
    // Set the text within the control.
    richTextBox1.set_SelectedText("This text contains a hanging indent."
        + "The first sentence of the paragraph is spaced normally.");
    richTextBox1.set_SelectedText("All subsequent lines of text are "
        + "indented based on the value of SelectionHangingIndent.");
    richTextBox1.set_SelectedText("After this paragraph the indent is "
        + "returned to normal spacing.\n");
    richTextBox1.set_SelectedText("Since this is a new paragraph the indent"
        + "is also applied to this paragraph.");
    richTextBox1.set_SelectedText("All subsequent lines of text are "
        + "indented based on the value of SelectionHangingIndent.");
} //WriteIndentedTextToRichTextBox

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: