C#如何清空多个textbox的中的文本!

2025-01-06 03:30:29
推荐回答(1个)
回答1:

详细代码如下:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace test{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){foreach (Control c in this.Controls)//遍历窗体上所有控件Controls为所有窗体上控件的集合{if (c is TextBox)//判断某个控件是否TextBox{
c.Text = ""; //清空TextBox里面文本内容}}}}}