如何在RichTextBox里面,实现加粗,斜体和下划线功能?

dvdvip 2009-03-04 09:18:25
如何在RichTextBox里面,实现加粗,斜体和下划线功能?就是用户选定一段文字后,点击三个按钮,分别实现加粗,斜体和下划线功能。



还有,C#做出来的程序,当字体同时有加粗,斜体和下划线格式。那么程序会不会出错?
...全文
975 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dvdvip 2009-03-05
  • 打赏
  • 举报
回复
gisyellow,谢谢了。当时已经结帖了,没有看到你的帖子。不好意思。
gisyellow 2009-03-04
  • 打赏
  • 举报
回复

FontStyle fontStyle;
private void button1_Click(object sender, EventArgs e)
{
fontStyle = (FontStyle)(fontStyle | FontStyle.Bold);
SetFont(fontStyle);
}

private void button2_Click(object sender, EventArgs e)
{
fontStyle = (FontStyle)(fontStyle | FontStyle.Italic);
SetFont(fontStyle);
}

private void button3_Click(object sender, EventArgs e)
{
fontStyle = (FontStyle)(fontStyle | FontStyle.Underline);
SetFont(fontStyle);
}

private void SetFont(FontStyle style)
{
richTextBox1.SelectionFont = new Font("Arial",richTextBox1.SelectionFont.Size, fontStyle);
}
cppfaq 2009-03-04
  • 打赏
  • 举报
回复

private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(Font, FontStyle.Bold); // 加粗
}

private void button2_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(Font, FontStyle.Italic); // 斜体
}

private void button3_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(Font, FontStyle.Underline); // 下划线
}

private void button4_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(Font,
FontStyle.Italic | FontStyle.Underline | FontStyle.Bold); // 加粗且斜体下划线
}

当字体同时有加粗,斜体和下划线格式,不会出错

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧