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);
}
怎么理解上面这段代码中样式的判断呢?fontStyleContent与fontStyleContent比较不是恒真吗?那么ELSE不就没有意义喽??
该怎么理解这个IF-ELSE啊!!!
{
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);
}
怎么理解上面这段代码中样式的判断呢?fontStyleContent与fontStyleContent比较不是恒真吗?那么ELSE不就没有意义喽??
该怎么理解这个IF-ELSE啊!!!
如果没有设置,则设置上。结果应该是:按钮按一次,格式就改变一次,就象一个开关。
主要是这个,相当于一个布尔值,来回切换
BtnFont如果是blod(加粗)的话,取反~BtnFont 地到什么呢