如何使用组合框更改 richTextBox 字体大小

How to use combobox to change the richTextBox font size

private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)//change font size
{          
    if (toolStripComboBox1.SelectedIndex == 0)
    {
        richTextBox1.SelectionFont = new Font("Comic Sans MS", 12);
    }

    if (toolStripComboBox1.SelectedIndex == 1)
    {
        richTextBox1.SelectionFont = new Font("Comic Sans MS", 19);
    }
}

这是我的代码,在这种情况下我必须点击“19”两次才能正常工作,我的代码有什么错误

private void toolStripComboBox1_Click(object sender, EventArgs e)
        {
            toolStripComboBox1.ComboBox.SelectionChangeCommitted += ComboBoxOnSelectionChangeCommitted;
        }


private void ComboBoxOnSelectionChangeCommitted(object o, EventArgs eventArgs)
        {
            switch (toolStripComboBox1.SelectedIndex)
            {
                case 0:
                    richTextBox1.SelectionFont = new Font("Comic Sans MS", 12);
                    break;
                case 1:
                    richTextBox1.SelectionFont = new Font("Comic Sans MS", 19);
                    break;
                default:
                    richTextBox1.SelectionFont = new Font("Comic Sans MS", 9);
                    break;
            }
        }

您也可以使用 if 而不是 switch,但我个人更喜欢在这种情况下使用 switch。