System.Enum:抽象類別,繼承 ValueType、實作 IComparable、IFormattable、IConvertible。

使用 FontStyle 列舉設定字型樣式:
[Flags]
public enum FontStyle {
Regular = 0, Bold = 1, Italic = 2, Underline = 4, Strikeout = 8
}
private void SetStyle(object sender, EventArgs e) {
ToolStripButton btn = sender as ToolStripButton;
FontStyle fontStyleContent = this.rchTxtContent.SelectionFont.Style;
FontStyle btnFont = (FontStyle)Enum.Parse(typeof(FontStyle), btn.Tag.ToString());
if ((fontStyleContent | btnFont) == fontStyleContent) {
fontStyleContent = ~btnFont & fontStyleContent; // 移除樣式
} else {
fontStyleContent = fontStyleContent | btnFont; // 加入樣式
}
this.rchTxtContent.SelectionFont = new Font(
this.rchTxtContent.SelectionFont.FontFamily,
this.rchTxtContent.SelectionFont.Size,
fontStyleContent,
this.rchTxtContent.SelectionFont.Unit);
}
利用位元運算切換字型樣式(加粗、斜體、底線、刪除線)。