RichTextBox.SelectionFont 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置当前选定文本或插入点的字体。
public:
 property System::Drawing::Font ^ SelectionFont { System::Drawing::Font ^ get(); void set(System::Drawing::Font ^ value); };
	[System.ComponentModel.Browsable(false)]
public System.Drawing.Font SelectionFont { get; set; }
	[System.ComponentModel.Browsable(false)]
public System.Drawing.Font? SelectionFont { get; set; }
	[<System.ComponentModel.Browsable(false)>]
member this.SelectionFont : System.Drawing.Font with get, set
	Public Property SelectionFont As Font
	属性值
表示应用到当前选定文本或在插入点后输入的文本的字体的 Font。
- 属性
 
示例
下面的代码示例更改文本选择的当前字体加粗样式设置或控件中 RichTextBox 插入点后输入的文本。 此示例要求代码包含在 中的方法中 Form。 该示例还要求RichTextBox已将名为 的 richTextBox1添加到 。Form
void ToggleBold()
{
   if ( richTextBox1->SelectionFont != nullptr )
   {
      System::Drawing::Font^ currentFont = richTextBox1->SelectionFont;
      System::Drawing::FontStyle newFontStyle;
      if (richTextBox1->SelectionFont->Bold)
      {
         newFontStyle = FontStyle::Regular;
      }
      else
      {
         newFontStyle = FontStyle::Bold;
      }
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( currentFont->FontFamily,currentFont->Size,newFontStyle );
   }
}
private void ToggleBold()
{
   if (richTextBox1.SelectionFont != null)
   {
      System.Drawing.Font currentFont = richTextBox1.SelectionFont;
      System.Drawing.FontStyle newFontStyle;
      if (richTextBox1.SelectionFont.Bold)
      {
         newFontStyle = FontStyle.Regular;
      }
      else
      {
         newFontStyle = FontStyle.Bold;
      }
      richTextBox1.SelectionFont = new Font(
         currentFont.FontFamily, 
         currentFont.Size, 
         newFontStyle
      );
   }
}
Private Sub ToggleBold()
   If richTextBox1.SelectionFont IsNot 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
	注解
如果当前文本选定内容指定了多个字体,则此属性为 null。 如果当前未选择任何文本,则此属性中指定的字体将应用于当前插入点以及插入点后在控件中键入的所有文本。 字体设置一直适用,直到属性更改为其他字体,或直到插入点移动到控件中的不同节。
如果在控件中选择了文本,则所选文本和在文本选择后输入的任何文本都将应用此属性的值。 可以使用此属性更改 中 RichTextBox文本的字体样式。 可以将控件中的文本设置为粗体、斜体和下划线。 还可以更改文本的大小和应用于文本的字体。
若要更改控件中文本的颜色,请使用 SelectionColor 属性。