三个按钮。以下为粗体按钮事件//设置粗体
private void button1_Click(object sender, EventArgs e)
{
Font bold = this.richTextBox1.SelectionFont;
if (bold.Bold)
{
if (bold.Italic)
{
if (bold.Underline)
{
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Italic | FontStyle.Underline);
}
else
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Italic);
}
else if (bold.Underline)
{
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Underline);
}
else
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Regular);
}
else if (bold.Italic)
{
if (bold.Underline)
{
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
}
else
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Bold | FontStyle.Italic);
}
else if (bold.Underline)
{
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Bold | FontStyle.Underline);
}
else
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Bold);
}其他2个按钮事件代码差不多。。当我切换输入法。选中字母和字体数字再单击按钮就报错。该如何解决?还有。。由于其他循环不怎么会。这代码用其他循环怎么写比较简洁一点?
private void button1_Click(object sender, EventArgs e)
{
Font bold = this.richTextBox1.SelectionFont;
if (bold.Bold)
{
if (bold.Italic)
{
if (bold.Underline)
{
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Italic | FontStyle.Underline);
}
else
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Italic);
}
else if (bold.Underline)
{
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Underline);
}
else
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Regular);
}
else if (bold.Italic)
{
if (bold.Underline)
{
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
}
else
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Bold | FontStyle.Italic);
}
else if (bold.Underline)
{
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Bold | FontStyle.Underline);
}
else
this.richTextBox1.SelectionFont = new Font(bold, FontStyle.Bold);
}其他2个按钮事件代码差不多。。当我切换输入法。选中字母和字体数字再单击按钮就报错。该如何解决?还有。。由于其他循环不怎么会。这代码用其他循环怎么写比较简洁一点?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货