一个程序中的片段,我单步执行了一下,顺序很乱,不是我原来想的那样,请问是怎么回事? void txtBox_Enter(object sender, EventArgs e)
        {
           
            if (((SWF.TextBox)sender).Multiline)
            {
                orgtext = ((SWF.TextBox)sender).Text;
            }            if (!((SWF.TextBox)sender).ReadOnly)
            {
                ((SWF.TextBox)sender).Clear();                ((SWF.TextBox)sender).Multiline = false;
                ((SWF.TextBox)sender).BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            }
        }

解决方案 »

  1.   

    我想改成这样写,你是否比较清楚点呢? void txtBox_Enter(object sender, EventArgs e)
            {
               SWF.TextBox txt=sender as SWF.TextBox;
               if(txt!=null)
               {
                   if(txt.Multiline)
                      orgtext=txt.Text;
                   if(txt.ReadOnly)
                   {
                      txt.Clear();
                      txt.Multiline=false;
                      txt.BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                }
             }
      

  2.   

    纠正
    if(txt.ReadOnly)
    -->
    if(!txt.ReadOnly)
      

  3.   

    确实这样代码很清晰,谢谢。我原意是要问程序执行的流程,原来以为应该是一句句顺序执行下来的,调试了一下发现不是这样,改变了Multiline 和 BorderStyle 属性好像会重新再从执行,反正是和想象中不一样了。请问是为什么?
      

  4.   

    这个要具体看SWF.TextBox的实现了,可能在实现里面有引发了Enter事件
      

  5.   

    就是原来的TextBox , SWF = System.Windows.Forms ,有时候还会从中间重新执行。比较奇怪...