Winform 设置 RichTextBox 控件字体大小和样式, 设置 FontStyle (粗体, 斜体, 下划线, 删除线), ForeColor (字体颜色)
新建窗体,拖拽一个 RichTextBox 控件到窗体
using System;
using System.Windows.Forms;
namespace DemoWinForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// 设置字体为“宋体”
this.richTextBox1.Font = new System.Drawing.Font("SimSun", 8.25F);
// 设置字体风格, 加粗
// System.Drawing.FontStyle.Regular = 常规
// System.Drawing.FontStyle.Bold = 加粗
// System.Drawing.FontStyle.Italic = 倾斜
// System.Drawing.FontStyle.Underline = 下划线
// System.Drawing.FontStyle.Strikeout = 删除线
this.richTextBox1.Font = new System.Drawing.Font(this.richTextBox1.Font, System.Drawing.FontStyle.Bold);
// 或者
// this.richTextBox1.Font = new System.Drawing.Font("SimSun", 8.25F, System.Drawing.FontStyle.Bold);
// 设置字体显示颜色为红色
this.richTextBox1.ForeColor = System.Drawing.Color.Red;
}
}
}