保存数据完成以后,如何恢复,重置 TextBox 的Text默认值(比如清空)好象没有重置Form的属性和方法,有什么办法?

解决方案 »

  1.   

    循环判断是不是TextBox控件,是就清空
      

  2.   

    WinForm怎么这么麻烦?只有这么一个办法吗?大家都是这么弄的吗?相比WebForm方便多了  window.location.href=window.location.href;
      

  3.   

    你可以调用 InitializeComponent();
    这是初始化窗体的。
    之前要删了所有的先this.SuppendLayOut();
    foreach(Control obj in this.Controls)
    {
          this.Controls.Remove(obj);
    }
    InitializeComponent();
    this.ResumeLayOut();
      

  4.   

    移除写错了。这样
    this.Controls.Clear();
      

  5.   

    this.SuspendLayout();
    this.Controls.Clear();
    this.InitializeComponent();
    this.ResumeLayout();
      

  6.   

    wuyazhe(我的宝贝叫阿刺) 的解決方法會將所有控件的Text刪除的﹐包括Label等﹐如下代碼應該能實現的要求﹕
    foreach(Control ctl in this.Controls )
    {
         if (ctl.GetType() == typeof(System.Windows.Forms.TextBox))
             ctl.Text = "";
    }
      

  7.   

    window.location.href=window.location.hrefWeb中是重定向到本页,是所有的都恢复了默认值了吧,那应该算是投机取巧的方法。WinForm你重新调InitializeComponent()试试
      

  8.   

    foreach(Control ctl in this.Controls )
    {
    if (ctl.GetType() == typeof(System.Windows.Forms.TextBox))
    {
    if(((TextBox)ctl).CanUndo == true)
    {
    ((TextBox)ctl).Undo();
    ((TextBox)ctl).ClearUndo();
    }
    }
    }
      

  9.   

    foreach (Control con in this.Controls)
    {
        if (con is TextBox)
            con.Text = "";
    }
      

  10.   

    多谢各位大侠指教,看来只好用一匹狼的方法了。
    我要在基类里,把他封装成 FormReload()的一个方法。以后省得麻烦。