RichTextBox.SelectionAlignment プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > RichTextBox.SelectionAlignment プロパティの意味・解説 

RichTextBox.SelectionAlignment プロパティ

現在選択されている内容またはカーソル位置に適用される配置を取得または設定します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Property SelectionAlignment As
 HorizontalAlignment
Dim instance As RichTextBox
Dim value As HorizontalAlignment

value = instance.SelectionAlignment

instance.SelectionAlignment = value
public HorizontalAlignment SelectionAlignment { get;
 set; }
public:
property HorizontalAlignment SelectionAlignment {
    HorizontalAlignment get ();
    void set (HorizontalAlignment value);
}
/** @property */
public HorizontalAlignment get_SelectionAlignment ()

/** @property */
public void set_SelectionAlignment (HorizontalAlignment
 value)
public function get SelectionAlignment
 () : HorizontalAlignment

public function set SelectionAlignment
 (value : HorizontalAlignment)

プロパティ値
HorizontalAlignment 値の 1 つ。

例外例外
例外の種類条件

InvalidEnumArgumentException

指定した値が HorizontalAlignment クラスに定義されている値ではありません。

解説解説

コントロール内で選択されている段落がない場合、このプロパティに設定した配置は、その設定が適用されている段落の後に作成された段落だけでなく、カーソルが挿入されている段落にも適用されます。たとえば、RichTextBox コントロールに 2 つの段落があり、カーソルが 2 番目の段落内にあるとします。SelectionAlignment プロパティを HorizontalAlignment.Center に設定すると、カーソルが挿入されている段落がコントロールの中央に揃えて配置されます。2 番目の段落の後に 3 番目の段落を作成すると、3 番目の段落もコントロールの中央に揃えて配置されます。

プロパティを設定するときにコントロール内で段落が選択されている場合は、選択されているすべての段落が、このプロパティの設定に基づいて配置されます。このプロパティを使用すると、RichTextBox で作成中のドキュメントの段落を揃えることができます。たとえば、ドキュメント内のすべての段落を中央に揃えて配置する場合は、コントロール内のすべての段落を選択し、SelectionAlignment プロパティを HorizontalAlignment.Center に設定します。

メモメモ

選択したテキストに、さまざまな配置の混在した段落が複数含まれている場合、SelectionAlignment は SelectionAlignment.Left を返します。

使用例使用例

RichTextBox 内でテキストを配置する方法を次のコード例に示します。この例では、richTextBox1 という名前の RichTextBox コントロールがフォームに追加されている必要があります。

Private Sub WriteCenteredTextToRichTextBox()
   ' Clear all text from the RichTextBox;
   richTextBox1.Clear()
   ' Set the foreground color of the text.
   richTextBox1.SelectionColor = Color.Red
   ' Set the alignment of the text that follows.
   richTextBox1.SelectionAlignment = HorizontalAlignment.Center
   ' Set the font for the text.
   richTextBox1.SelectionFont = new Font("Lucinda
 Console", 12)
   ' Set the text within the control.
   richTextBox1.SelectedText = "This text is centered using the
 SelectionAlignment property."

End Sub
private void WriteCenteredTextToRichTextBox()
{
   // Clear all text from the RichTextBox;
   richTextBox1.Clear();
   // Set the foreground color of the text.
   richTextBox1.ForeColor = Color.Red;
   // Set the alignment of the text that follows.
   richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
   // Set the font for the text.
   richTextBox1.SelectionFont = new Font("Lucinda Console",
 12);
   // Set the text within the control.
   richTextBox1.SelectedText = "This text is centered using
 the SelectionAlignment property.\n";
}
private:
   void WriteCenteredTextToRichTextBox()
   {
      // Clear all text from the RichTextBox;
      richTextBox1->Clear();

      // Set the foreground color of the text.
      richTextBox1->ForeColor = Color::Red;

      // Set the alignment of the text that follows.
      richTextBox1->SelectionAlignment = HorizontalAlignment::Center;

      // Set the font for the text.
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Lucinda
 Console",12 );

      // Set the text within the control.
      richTextBox1->SelectedText = "This text is centered using
 the SelectionAlignment property.\n";
   }
private void WriteCenteredTextToRichTextBox()
{
    // Clear all text from the RichTextBox;
    richTextBox1.Clear();
    // Set the foreground color of the text.
    richTextBox1.set_ForeColor(Color.get_Red());
    // Set the alignment of the text that follows.
    richTextBox1.set_SelectionAlignment(HorizontalAlignment.Center);
    // Set the font for the text.
    richTextBox1.set_SelectionFont(new Font("Lucinda Console",
 12));
    // Set the text within the control.
    richTextBox1.set_SelectedText("This text is centered using
 the"
        + "SelectionAlignment property.\n");
} //WriteCenteredTextToRichTextBox
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RichTextBox クラス
RichTextBox メンバ
System.Windows.Forms 名前空間
HorizontalAlignment 列挙体



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

RichTextBox.SelectionAlignment プロパティのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



RichTextBox.SelectionAlignment プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS