RichTextBox.SelectionFont プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As RichTextBox Dim value As Font value = instance.SelectionFont instance.SelectionFont = value
/** @property */ public Font get_SelectionFont () /** @property */ public void set_SelectionFont (Font value)
現在選択されているテキストまたはカーソル位置以降に入力されるテキストに適用されるフォントを表す Font。

現在選択されているテキストに複数のフォントが指定されている場合、このプロパティは null 参照 (Visual Basic では Nothing) になります。テキストが現在選択されていない場合、このプロパティに指定されたフォントは、現在のカーソル位置と、カーソル位置以降にコントロールに入力されるすべてのテキストに適用されます。プロパティの値が異なるフォントに変更されるまで、またはカーソル位置をコントロール内の別の場所に移動するまでの間は、このフォントの設定が適用されます。
コントロール内でテキストが選択されている場合は、選択されているテキスト、およびテキストを選択した後に入力したすべてのテキストに対して、このプロパティの値が適用されます。このプロパティを使用して、RichTextBox 内のテキストのフォント スタイルを変更できます。コントロール内のテキストに、太字、斜体、および下線付きの属性を適用できます。また、テキストのポイント数や、テキストに適用するフォントも変更できます。

RichTextBox コントロール内で選択されているテキストまたはカーソル位置以降に入力されるテキストについて、現在設定されている太字フォント スタイルを変更するコード例を次に示します。この例では、コードが Form のメソッド内に含まれている必要があります。また、richTextBox1 という名前の RichTextBox が、Form に追加されている必要もあります。
Private Sub ToggleBold() If Not richTextBox1.SelectionFont Is Nothing Then Dim currentFont As System.Drawing.Font = richTextBox1.SelectionFont Dim newFontStyle As System.Drawing.FontStyle If richTextBox1.SelectionFont.Bold = True Then newFontStyle = FontStyle.Regular Else newFontStyle = FontStyle.Bold End If richTextBox1.SelectionFont = New Font( _ currentFont.FontFamily, _ currentFont.Size, _ newFontStyle _ ) End If End sub
private void ToggleBold() { if (richTextBox1.SelectionFont != null) { System.Drawing.Font currentFont = richTextBox1.SelectionFont; System.Drawing.FontStyle newFontStyle; if (richTextBox1.SelectionFont.Bold == true) { newFontStyle = FontStyle.Regular; } else { newFontStyle = FontStyle.Bold; } richTextBox1.SelectionFont = new Font( currentFont.FontFamily, currentFont.Size, newFontStyle ); } }
void ToggleBold() { if ( richTextBox1->SelectionFont != nullptr ) { System::Drawing::Font^ currentFont = richTextBox1->SelectionFont; System::Drawing::FontStyle newFontStyle; if ( richTextBox1->SelectionFont->Bold == true ) { newFontStyle = FontStyle::Regular; } else { newFontStyle = FontStyle::Bold; } richTextBox1->SelectionFont = gcnew System::Drawing::Font( currentFont->FontFamily,currentFont->Size,newFontStyle ); } }
private void ToggleBold() { if (richTextBox1.get_SelectionFont() != null) { System.Drawing.Font currentFont = richTextBox1.get_SelectionFont(); System.Drawing.FontStyle newFontStyle; if (richTextBox1.get_SelectionFont().get_Bold() == true) { newFontStyle = FontStyle.Regular; } else { newFontStyle = FontStyle.Bold; } richTextBox1.set_SelectionFont( new Font(currentFont.get_FontFamily(), currentFont.get_Size(), newFontStyle)); } } //ToggleBold

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.SelectionFont プロパティを検索する場合は、下記のリンクをクリックしてください。

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