请各位熟悉的朋友帮忙解释一下

解决方案 »

  1.   

    ~ 运算符对操作数执行按位求补运算,其效果相当于反转每一位
    & 运算符既可作为一元运算符也可作为二元运算符。一元 & 运算符返回操作数的地址
    为整型和 bool 类型预定义了二进制 & 运算符。对于整型,& 计算操作数的逻辑按位“与”。对于 bool 操作数,& 计算操作数的逻辑“与”;也就是说,当且仅当两个操作数均为 true 时,结果才为 true。 & 运算符计算两个运算符,与第一个操作数的值无关。
      

  2.   

    oldFont.Style & ~FontStyle.Bold&是二进制按位与运算符,~是二进制按位取反运算符。这个表达式应该是想把oldFont.Style中的Bold设为没有吧。
    呵呵,如果FontStyle是个加了[Flag]的枚举,这还真是个好办法。楼主先去了解一下Flag特性才好理解这个表达式
      

  3.   

    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",为什么它们就能完成这个任务
      

  4.   

    你可以这样想,其实FontStyle就是一个二进制数。假设第一位是斜体,即000001为斜体,第二位是粗体,即000010为粗体,000011又粗又斜。首先对表示粗体的000010取反,就成了111101,然后再与某个Style进行按位与,按位与的特点就是如果前后两个二进制数的某一位都为1,结果才为1,很显然可以看出来,任何数与111101进行按位与的话,结果就是把第二位置0,这样就达到了取消黑体的效果。
      

  5.   

    谢谢楼上的朋友,呵呵查了下文档,有这几个方法
    Font (Font, FontStyle)  初始化新 Font,它使用指定的现有 Font 和 FontStyle 枚举。  
    Font (FontFamily, Single)  使用指定的大小初始化新 Font。  
    Font (String, Single)  使用指定的大小初始化新 Font。  
    然后在VS中看提示,上面代码中实际使用的又是(string,fload),我现在搞不清oldFont、oldFont.Style、FontStyle.Bold的实际数据类型是什么,在上面代码中的取值又是什么?弄清这个问题结贴了,呵呵
      

  6.   

    很显然是FontStyle这个枚举类型的。
      

  7.   

    那在更MSDN文档里的构造函数对不上了啊?
    你说它实际用的是那个构造函数?
      

  8.   

    二进制   |   运算符是为整型和   bool   类型预定义的。对于整型,|   对操作数进行按位“或”运算。对于   bool   操作数,|   对操作数进行逻辑“或”计算,也就是说,当且仅当两个操作数均为   false   时,其结果才为   false。   
        
      一元   &   运算符返回操作数的地址(要求   unsafe   上下文)。   
        
      为整型和   bool   类型预定义了二进制   &   运算符。对于整型,&   计算操作数的按位“与”。对于   bool   操作数,&   计算操作数的逻辑“与”;也就是说,当且仅当两个操作数均为   true   时,其结果才为   true。  ~   运算符对操作数执行按位求补操作。为   int、uint、long   和   ulong   预定义了按位求补运算符
      

  9.   

    楼主基础太差
    Ivony好有耐心,佩服~
      

  10.   

    什么是mask 有人用mask来解释这个问题