Export (0) Print
Expand All

RichTextBox.SelectionRightIndent Property

The distance (in pixels) between the right edge of the RichTextBox control and the right edge of the text that is selected or added at the current insertion point.

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

public int SelectionRightIndent { get; set; }
/** @property */
public int get_SelectionRightIndent ()

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

public function get SelectionRightIndent () : int

public function set SelectionRightIndent (value : int)

Not applicable.

Property Value

The indentation space, in pixels, at the right of the current selection or 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 SelectionIndent 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 create a right margin in a RichTextBox using the SelectionRightIndent property. The example requires that you have a form that contains a RichTextBox control named richTextBox1, and that the example code is called from an event within the form's class.

private void WriteIndentedTextToRichTextBox()
{
    // Clear all text from the RichTextBox;
    richTextBox1.Clear();
    // Specify a 20 pixel right indent in all paragraphs.
      richTextBox1.SelectionRightIndent = 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 right edge of the RichTextBox.";
    richTextBox1.SelectedText = "You can use this property with the SelectionIndent property to provide right and left margins.";
    richTextBox1.SelectedText = "After this paragraph the indentation will end.\n\n";
    // Remove all right indentation.
    richTextBox1.SelectionRightIndent = 0;
    richTextBox1.SelectedText = "This paragraph has no right indentation. All text should flow as normal.";
}

private void WriteIndentedTextToRichTextBox()
{
    // Clear all text from the RichTextBox;
    richTextBox1.Clear();
    // Specify a 20 pixel right indent in all paragraphs.
    richTextBox1.set_SelectionRightIndent(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 "
        + "right edge of the RichTextBox.");
    richTextBox1.set_SelectedText("You can use this property with the "
        + "SelectionIndent property to provide right and left margins.");
    richTextBox1.set_SelectedText("After this paragraph the indentation "
        + "will end.\n\n");
    // Remove all right indentation.
    richTextBox1.set_SelectionRightIndent(0);
    richTextBox1.set_SelectedText("This paragraph has no right indentation."
        + "All text should flow as normal.");
} //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

Community Additions

ADD
Show:
© 2015 Microsoft