RichTextBox.SelectionAlignment プロパティ
現在選択されている内容またはカーソル位置に適用される配置を取得または設定します。
名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
Dim instance As RichTextBox Dim value As HorizontalAlignment value = instance.SelectionAlignment instance.SelectionAlignment = value
public: property HorizontalAlignment SelectionAlignment { HorizontalAlignment get (); void set (HorizontalAlignment value); }
/** @property */ public HorizontalAlignment get_SelectionAlignment () /** @property */ public void set_SelectionAlignment (HorizontalAlignment value)


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

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

Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からRichTextBox.SelectionAlignment プロパティを検索する場合は、下記のリンクをクリックしてください。

- RichTextBox.SelectionAlignment プロパティのページへのリンク