private void buttonBold_Click(object sender, EventArgs e)
{
Font oldFont;
Font newFont;
// Get the font that is being used in the selected text
oldFont = this.richTextBoxText.SelectionFont;
// If the font is using bold style now, we should remove the
// Formatting
if (oldFont.Bold)
newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Bold);
else
newFont = new Font(oldFont, oldFont.Style | FontStyle.Bold);
// Insert the new font and return focus to the RichTextBox
this.richTextBoxText.SelectionFont = newFont;
this.richTextBoxText.Focus();
}
//黑体与非黑体的转换,不太理解的是"oldFont.Style & ~FontStyle.Bold"和"oldFont.Style | FontStyle.Bold",为什么它们就能完成这个任务