使用复选框更改字体样式

change the font style using check box

您好,我想将富文本框中的文字字体改为粗体、斜体、下划线。我有以下代码。但是如果我点击另一个复选框,第一个复选框的变化就会消失。我可以知道如何解决吗

    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);
    }

您可以尝试从 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);
}