共用方式為


HOW TO:使用 Windows Form RichTextBox 控制項設定縮排、首行縮排和分項段落

更新:2007 年 11 月

Windows Form RichTextBox 控制項有各種選項可格式化其所顯示的文字。您可藉由設定 SelectionBullet 屬性來將選取的段落格式化為項目符號清單。您也可使用 SelectionIndentSelectionRightIndentSelectionHangingIndent 屬性來相對於控制項的左右邊緣和其他行文字的左邊緣,設定段落的縮排。

若要將段落格式化為項目符號清單

  • SelectionBullet 屬性設定為 true。

    RichTextBox1.SelectionBullet = True
    
    richTextBox1.SelectionBullet = true;
    
    richTextBox1->SelectionBullet = true;
    

若要縮排段落

  1. SelectionIndent 屬性設定為表示控制項左邊緣和文字左邊緣之間像素距離的整數。

  2. SelectionHangingIndent 屬性設定為表示段落第一行文字左邊緣和同一段落中後續幾行左邊緣之間像素距離的整數。SelectionHangingIndent 屬性的值只會套用至段落中在第一行之下換行的文字。

  3. SelectionRightIndent 屬性設定為表示控制項右邊緣和文字右邊緣之間像素距離的整數。

    RichTextBox1.SelectionIndent = 8
    RichTextBox1.SelectionHangingIndent = 3
    RichTextBox1.SelectionRightIndent = 12
    
    richTextBox1.SelectionIndent = 8;
    richTextBox1.SelectionHangingIndent = 3;
    richTextBox1.SelectionRightIndent = 12;
    
    richTextBox1->SelectionIndent = 8;
    richTextBox1->SelectionHangingIndent = 3;
    richTextBox1->SelectionRightIndent = 12;
    
    注意事項:

    上述所有屬性都會影響任何包含選取文字的段落,而且也會影響在目前插入點之後輸入的文字。例如,當使用者選取段落中的一個字並接著調整縮排時,新的設定值會套用至包含這個字的整個段落,以及在選取段落之後輸入的任何後續段落。如需利用程式設計方式選取文字的詳細資訊,請參閱 TextBoxBase.Select 方法

請參閱

參考

RichTextBox

其他資源

RichTextBox 控制項 (Windows Form)

在 Windows Form 上使用的控制項