C#WinForm练习——点击button按钮使窗体中文本框都显示“好好学习,天天向上”
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Button按钮:当点击按钮窗体中的文本框都显示“好好学习,天天向上”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//循环遍历窗体中所有的控件 this.Controls指这个窗体中所有的控件
foreach (Control item in this.Controls)
{
//如果是文本框
if (item is TextBox)
{
((TextBox)item).Text = "好好学习,天天向上";
}
}
}
}
}