取消选中C#中的复选框并清除文本框 [英] uncheck checkboxes and clear textboxes in C#

查看:785
本文介绍了取消选中C#中的复选框并清除文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当点击重置按钮时,我需要c#中的代码重置复选框和文本框请帮助人员。

I need a code in c# to reset checkboxes and textboxes when a reset button is clicked pls help guys.

推荐答案

我们无法提供详细信息 - 我们不知道不知道你的应用程序,以及它是如何配置的。

你可以做一些事情:

We can't provide detail - we don't know your application, and how it is configured.
There are some things you can do:
Checkbox.Checked = false;



将重置单个复选框状态。


will reset an individual checkbox state.

TextBox.Text = "";

将重置单个文本框。



你可以遍历Controls数组:

Will reset an individual Textbox.

You can loop through the Controls array:

foreach (Control c in Controls)
   {
   if (c is CheckBox)
      {
      ((CheckBox) c).Checked = false;
      }
   else if (c is TextBox)
      {
      ((TextBox) c).Text = "";
      }
   }

你可以修改它以处理Panels和其他容器控件中的那些。

如果自定义控件中有CheckBoxes或文本字段但是,你必须按照自己的方式处理它们。

And you can modify this to handle those inside Panels and other container controls.
If you have CheckBoxes or text fields inside custom controls, though, you will have to work out your own way of dealing with them.


对于一个文本框



这个。 textbox1.text =;



复选框



this.checkbox.checked = false ;
For a text box

this.textbox1.text = "";

For a check box

this.checkbox.checked = false;


在重置按钮事件处理程序上



On the reset button event handler

protected void reset_Click(objest sender, EventArgs e)
{
  textBox1.Text = "";
  textBox2.Text = "";
  checkBox1.IsChecked = false;
  ....
}





执行以上代码



Do the above code


这篇关于取消选中C#中的复选框并清除文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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