重置表格中的文本控件 [英] reset text controls in a form

查看:72
本文介绍了重置表格中的文本控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我在C#中有一个表单,其中包含太多的文本框和组合框,无法输入和编辑数据.因此清除所有输入的数据并不容易:

Hi All
I have a form in C# with too many textBoxes and comboboxes to enter and edit data.so it not simple to clear all entered data like this:

textbox1.text="";


我想通过单击一个按钮清除所有输入的数据.请告诉我我该怎么做.
感谢所有


i want to clear all entered data from them by clicking on a button.please tell me how can i do that.
thanks all

推荐答案

从其他答案中,您可能已经掌握了要使用的技术.

From other answers, you probably got the techniques to use.

问题更加严重:从概念上讲,为什么需要重置?那是什么.

The problem is deeper: why do you need reset and what is that, conceptually.

针对一个类似的问题,我深入讨论了这个话题;请参阅 http://java.codeproject.com/Answers/305562/clearing- the-Csharp-form-contorls#answer3 [ ^ ].

I discussed this topic in depth, in response to a similar question; please see http://java.codeproject.com/Answers/305562/clearing-the-Csharp-form-contorls#answer3[^].


您可以循环进行控制

You can loop for control

foreach (Control ctrl in this)
{
        if(ctrl is TextBox)
                (ctrl as TextBox).Clear();
}


您可以编写循环以遍历表单中的所有控件,然后根据控件类型决定要执行的操作.
我将让您找出要放入大小写值的内容.

You could write a loop to go through all the controls in the form and then decide what to do based on the control type.
I''ll leave you to figure out what to put in the case values.

foreach( Control ctl in Controls )
{
   switch( ctl.GetType() )
   {
      case "TextBox": 
         ((TextBox)ctl).Text = string.Empty;

      case "ComboBox":
         ((ComboBox)ctl.SelectedIndex = -1;

      ...

   }
}


这篇关于重置表格中的文本控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆