次の方法で共有


RichTextBox.SelectionIndent プロパティ

RichTextBox の左端から、現在選択されているテキストの左端またはカーソル位置以降に追加されたテキストの左端までの距離をピクセル単位で取得または設定します。

Public Property SelectionIndent As Integer
[C#]
public int SelectionIndent {get; set;}
[C++]
public: __property int get_SelectionIndent();public: __property void set_SelectionIndent(int);
[JScript]
public function get SelectionIndent() : int;public function set SelectionIndent(int);

プロパティ値

現在選択されているテキストの左、またはカーソル位置の左に適用されているインデントの現在の幅 (ピクセル単位)。

解説

テキストが現在選択されていない場合、インデントの設定は、カーソルがある段落と、カーソル位置以降にコントロールに入力されるすべてのテキストに適用されます。プロパティの値が変更されるまで、またはカーソル位置をコントロール内の別の段落に移動するまでの間は、このインデントの設定が適用されます。

コントロール内でテキストが選択されている場合は、選択されているテキスト、およびテキストを選択した後に入力したすべてのテキストに対して、このプロパティの値が適用されます。このプロパティを使用して、 RichTextBox のドキュメント内に含まれている段落のインデントを設定できます。このプロパティを SelectionRightIndent と組み合わせて使用すると、段落内に表示される段落を作成できます。

コントロール内の段落にぶら下げインデントを設定するには、 SelectionHangingIndent プロパティを使用します。

使用例

[Visual Basic, C#, C++] SelectionIndent プロパティを使用して、 RichTextBox 内でインデント テキストを指定する方法を次の例に示します。この例は、 richTextBox1 という名前の RichTextBox コントロールがフォームに追加されていることを前提にしています。

 
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

[C#] 
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.";
}

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

RichTextBox クラス | RichTextBox メンバ | System.Windows.Forms 名前空間 | SelectionRightIndent | SelectionHangingIndent