C#点击按钮定时器1秒一刷新,textbox的值怎么不变呀?
点击按钮,会出来10textbox,但是怎么不刷新呢?
程序如下:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
class Tex : TextBox
{
int x;
public Tex(int in_x)
{
x = in_x;
}
}
Tex[] Texts;
void caiji()
{
//Controls.Clear();
int shang = 100;
int x = 50;
int y = 50;
Texts = new Tex[10];
Random rd = new Random();
for (int i = 0; i < 10; i++)
{
//创建text
Tex newText = new Tex(i);
//newText.Clear();
// newText.Text = Convert.ToString (++m);
newText.Text = Convert.ToString(rd.Next(100, 200));
//foreach (Tex Tex in Texts)
//{
//}
//设定text的位置
newText.Location = new Point(100 + shang * i, 100);
//设定text大小
newText.Size = new Size(x, y);
//newText.BackColor = Color.LightGray;
//将新按钮添加到窗体
this.Controls.Add(newText);
//继承
//添加到数组
//Texts[i] = newText;
//不仅要添加到窗体,也要添加到数
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1000;
}
private void timer1_Tick(object sender, EventArgs e)
{
caiji();
}
}
}