|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
timer没有启动怎么回事?
编译没有发现问题
namespace WinFormsApp_Timer01
{
public partial class Form1 : Form
{
//定义全局变量
int iCount;
int iCountMax;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int i = 1;
for (i = 1; i<=100; i++)
{
comboBox1.Items.Add(i.ToString() + "秒");
lblTimRemain.Text = iCountMax.ToString();
}
}
private void btn_Click(object sender, EventArgs e)
{
string strTimeItemText = comboBox1.Text;
int iTimeItemTextLen = comboBox1.Text.Length;
string strTimeItemTextNew = comboBox1.Text.Remove(iTimeItemTextLen - 1, 1);
iCountMax = Convert.ToUInt16(strTimeItemTextNew);
iCount = iCountMax;
progressBar1.Maximum = iCountMax;
lblTimRemain.Text = iCountMax.ToString() + " 秒";
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Value = iCount;
lblTimRemain.Text = iCount.ToString() + " 秒";
iCount--;
if (iCount<=0)
{
timer1.Stop();
MessageBox.Show("时间到达");
}
}
}
}
|
|