求c#一段小程序!请高手帮忙!
来源:百度知道 编辑:UC知道 时间:2024/05/21 07:04:09
在设计器里加个按钮,加个timer控件以及加个标签就可以了
以下是触发事件的代码,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 计数
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = new Random().Next(1, 11).ToString();
}
}
}
放一个文本框控件,textBox1,一个计时器控件timer1,设置timer1的enable为false,按钮的点击事件里:this.timer1.Enabled = true;
timer1的timer1_Tic