private void btnBold_Click(object sender, EventArgs e)
{
Font oldfont, newfont;
oldfont = this.richTextBox1.SelectionFont;//获取选定字的字体格式
if (oldfont.Bold)
{
newfont = new Font(oldfont, oldfont.Style &~FontStyle.Bold);//清除粗体字格式
}
else
newfont = new Font(oldfont, oldfont.Style | FontStyle.Bold); //设置为粗体字格式
richTextBox1.SelectionFont = newfont;
richTextBox1.Focus();
}
private void btnUnderline_Click(object sender, EventArgs e)
{
Font oldfont, newfont;
oldfont = this.richTextBox1.SelectionFont;//获取选定字的字体格式
if (oldfont.Underline)
{
newfont = new Font(oldfont, oldfont.Style & ~FontStyle.Underline);//清除下划线字格式
}
else
newfont = new Font(oldfont, oldfont.Style | FontStyle.Underline); //设置为下划线字格式
richTextBox1.SelectionFont = newfont;
richTextBox1.Focus();
}
private void btnItalic_Click(object sender, EventArgs e)
{
Font oldfont, newfont;
oldfont = this.richTextBox1.SelectionFont;//获取选定字的字体格式
if (oldfont.Italic)
{
newfont = new Font(oldfont, oldfont.Style & ~FontStyle.Italic);//清除斜体字格式
}
else
newfont = new Font(oldfont, oldfont.Style | FontStyle.Italic); //设置为斜体字字格式
richTextBox1.SelectionFont = newfont;
richTextBox1.Focus();
}
private void btnCenter_Click(object sender, EventArgs e)
{
if (richTextBox1.SelectionAlignment == HorizontalAlignment.Left)
richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
else
richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
richTextBox1.Focus();
}
{
Font oldfont, newfont;
oldfont = this.richTextBox1.SelectionFont;//获取选定字的字体格式
if (oldfont.Bold)
{
newfont = new Font(oldfont, oldfont.Style &~FontStyle.Bold);//清除粗体字格式
}
else
newfont = new Font(oldfont, oldfont.Style | FontStyle.Bold); //设置为粗体字格式
richTextBox1.SelectionFont = newfont;
richTextBox1.Focus();
}
private void btnUnderline_Click(object sender, EventArgs e)
{
Font oldfont, newfont;
oldfont = this.richTextBox1.SelectionFont;//获取选定字的字体格式
if (oldfont.Underline)
{
newfont = new Font(oldfont, oldfont.Style & ~FontStyle.Underline);//清除下划线字格式
}
else
newfont = new Font(oldfont, oldfont.Style | FontStyle.Underline); //设置为下划线字格式
richTextBox1.SelectionFont = newfont;
richTextBox1.Focus();
}
private void btnItalic_Click(object sender, EventArgs e)
{
Font oldfont, newfont;
oldfont = this.richTextBox1.SelectionFont;//获取选定字的字体格式
if (oldfont.Italic)
{
newfont = new Font(oldfont, oldfont.Style & ~FontStyle.Italic);//清除斜体字格式
}
else
newfont = new Font(oldfont, oldfont.Style | FontStyle.Italic); //设置为斜体字字格式
richTextBox1.SelectionFont = newfont;
richTextBox1.Focus();
}
private void btnCenter_Click(object sender, EventArgs e)
{
if (richTextBox1.SelectionAlignment == HorizontalAlignment.Left)
richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
else
richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
richTextBox1.Focus();
}
未完,待续................
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步