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”才能使其正常工作,我的代码有什么错误
答案 0 :(得分:0)
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代替,但是我个人更希望在这种情况下进行切换。