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啊!!!

解决方案 »

  1.   

    if ((fontStyleContent | BtnFont) == fontStyleContent) 用于比较 BtnFont (即 btn.Tag 中的内容)中所指定的位是否设置。
      

  2.   

    这段程序的意思是:如果 btn.Tag 指定的格式已经设置,则把它们去掉;
    如果没有设置,则设置上。结果应该是:按钮按一次,格式就改变一次,就象一个开关。
      

  3.   

    fontStyleContent = ~BtnFont & fontStyleContent; 
    主要是这个,相当于一个布尔值,来回切换
      

  4.   

    还是不明白???
    BtnFont如果是blod(加粗)的话,取反~BtnFont 地到什么呢