C# textBox 中批量撤销,清空数据
看代码如下:
        private void button1_Click(object sender, EventArgs e)
         {
             //this.textBox1.Undo();             //成功
             //this.textBox2.Undo();             //成功
             ........
             //this.textBox.Text=string.Empty;   //成功
             ........
            //当textBox控件太多的时候,用下面的方法获取TextBox类型的控件,然后清空数据,但撤销却报错
             foreach(Control col in this.Controls)
             {
                 if (col is TextBox)
                 {
                     col.Text = string.Empty;
                     col.Undo();//出错
                 }
             }              
         }
------解决方案--------------------  {  
           //this.textBox1.Undo();            //成功  
           //this.textBox2.Undo();            //成功  
           ........  
           //this.textBox.Text=string.Empty;  //成功  
           ........  
         //当textBox控件太多的时候,用下面的方法获取TextBox类型的控件,然后清空数据,但撤销却报错  
           foreach(Control col in this.Controls)  
           {  
               if (col is TextBox)  
               {  
                   (col as TextBox).Text = string.Empty;  
                   (col as TextBox).Undo();//出错  
               }  
           }            
       }