为什么我c#中的timer控件无效? 5
{
timer1.Enabled = true;
timer1.Interval = 10000;
}
private void timer1_Tick(object sender, EventArgs e)
{
MessageBox.Show("时间到");
}
---------------------------------------
时间到了,也没有messagebox弹出来,
使用的是vs2019 展开
设置timer控件属性:Enabled:True,其余默认.
在timer控件事件:Tick事件中添加代码:
private void timer1_Tick(object sender, EventArgs e)
{
string str = DateTime.Now.ToString();
this.textBox1.Text = str;
}
然后运行.
效果:在textBox1中显示当前的日期和时间.
我试了,没有任何问题!
timer属性
代码:
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 WindowsFormsApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.numLabel.Text = 0.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.numLabel.Text = (Convert.ToInt32(this.numLabel.Text.Trim()) + 1).ToString();
MessageBox.Show("Time is on");
}
}
}