RichTextBox控件用法

发布时间:2010年08月17日      浏览次数:442 次
//取消或置为粗体
private void button2_Click(object sender, System.EventArgs e)
{
Font oldFont = this.richTextBox1.SelectionFont;
Font newFont;
if (oldFont.Bold)
       newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Bold);
else
       newFont = new Font(oldFont,oldFont.Style | FontStyle.Bold);
this.richTextBox1.SelectionFont = newFont;
this.richTextBox1.Focus();
}
//取消或置为斜体
private void button7_Click(object sender, System.EventArgs e)
{
Font oldFont = this.richTextBox1.SelectionFont;
Font newFont;
if (oldFont.Italic)
       newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Italic);
else
       newFont = new Font(oldFont,oldFont.Style | FontStyle.Italic);
this.richTextBox1.SelectionFont = newFont;
this.richTextBox1.Focus();
}
//取消或加上下划线
private void button8_Click(object sender, System.EventArgs e)
{
Font oldFont = this.richTextBox1.SelectionFont;
Font newFont;
if (oldFont.Underline)
       newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Underline);
else
       newFont = new Font(oldFont,oldFont.Style | FontStyle.Underline);
this.richTextBox1.SelectionFont = newFont;
this.richTextBox1
       .Focus();
}
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!