C#入门经典第四版中359页一个textBox的例子,说为了防止用户在输入完信息之前单击OK,要先把OK按钮的Enabled属性设置为false,这应在窗体的构造函数中设置,而不是Properties窗口中设置。
请问这是为何?如果在Properties设置了false,不也能通过代码            this.btnOK.Enabled = true来使得必要的时候启用该按钮么?还有,这个例子中的几个处理文本框的程序开头
private void txtBoxAge_KeyPress(object sender, KeyPressEventArgs e)
参数里的sender和e都是干吗用的?哪儿有提到这块知识?
我是看到第10章,OOP的一部分实在看不下去了,太抽象无法理解,就直接看win部分了初涉C#,OOP的很多概念都转不过弯来,谢谢各位指点!

解决方案 »

  1.   

    它的意思说,比如:protected void btn_Click(object sender,EventArgs e)
    {
       try
       {
            this.btn.Enabled =false;
            //你处理的代码
        }
       catch(Exception ex)
      {
        throw ex;
      }
       finally 
      {
        this.btn.Enabled =true;
      }
      
    }
    sender是指触发这个事件的对象,你可以通过它来得到是哪个触发了这个事件
    KeyPressEventArgs 是相应事件的参数。
      

  2.   

    protected void btn_Click(object sender,EventArgs e)
    {
      try
      {
      this.btn.Enabled =false;
      //你处理的代码
      }
      catch(Exception ex)
      {
      throw ex;
      }
      finally  
      {
      this.btn.Enabled =true;
      }
       
    }
    sender是指触发这个事件的对象,你可以通过它来得到是哪个触发了这个事件
    KeyPressEventArgs 是相应事件的参数。
    理解一下