嗨我想将富文本框中文本的文本字体更改为粗体,斜体,下划线。我有以下代码。但是,如果我单击另一个复选框,第一个复选框更改消失。我可以知道如何解决它
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
richTextBox1.Font = new Font(richTextBox1.Font, FontStyle.Bold);
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
richTextBox1.Font = new Font(richTextBox1.Font, FontStyle.Italic);
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
richTextBox1.Font = new Font(richTextBox1.Font, FontStyle.Underline);
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
richTextBox1.Font = new Font(richTextBox1.Font, FontStyle.Regular);
}
答案 0 :(得分:0)
您可以尝试从checkBox_CheckedChanged
调用这样的方法private void UpdateFont()
{
System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular;
if (checkBox1.Checked) style |= System.Drawing.FontStyle.Bold;
if (checkBox2.Checked) style |= System.Drawing.FontStyle.Italic;
if (checkBox3.Checked) style |= System.Drawing.FontStyle.Underline;
textBox1.Font = new Font(textBox1.Font, style);
}