该控件的启动与关闭分别是.start(),.stop(),可是我在用的时候有点问题。具体如下:textBox_textChanged()
{
timer.start();
}
上述代码目的是实现textBox接收到数据后启动timer设置好timer的关联事件是button_click(),时间间隔interval是20秒,如下:
button_click()
{
textBox.Text = "";
timer.stop();
}这样,textBox接收到数据后启动timer,20秒后清空textBox,并通过timer.stop()关闭timer,当textBox接收到数据后重新启动timer,反复循环。结果是textBox接收到数据后timer启动20秒后清空textBox,然后关闭timer,但是当textBox再次接收到数据后无法启动timer。这是为什么?在属性中已经设置timer.enabled = true;请高手指点希望能给出具体代码
{
timer.start();
}
上述代码目的是实现textBox接收到数据后启动timer设置好timer的关联事件是button_click(),时间间隔interval是20秒,如下:
button_click()
{
textBox.Text = "";
timer.stop();
}这样,textBox接收到数据后启动timer,20秒后清空textBox,并通过timer.stop()关闭timer,当textBox接收到数据后重新启动timer,反复循环。结果是textBox接收到数据后timer启动20秒后清空textBox,然后关闭timer,但是当textBox再次接收到数据后无法启动timer。这是为什么?在属性中已经设置timer.enabled = true;请高手指点希望能给出具体代码
解决方案 »
- 求教!c#指定多声卡(总共6个声卡)!可以同时分别播放不同的MP3音乐。
- textBox固定显示最后几行的时候滚动条老是在跳
- 使用Connector/NET存储byte[]为blob的问题,存储前后数据不一致
- 宿主是什么?
- WPF C#中如何设置DataGrid某一行的高度?
- 运行时,拖动复制按钮的问题。复制完成以后,原按钮状态仍处于被拖动状态。
- sxw888请进,这个怎么改?
- 帮忙推荐一本好书
- e1的内容为 "对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成。"是什么意思
- SqlCommand的带参数的插入语句怎么写呢?
- 上一页参数传到下一页
- C#字符串里面是HTML源码如何截取A标签的链接
{
}这个你没有用上吗?
{
textBox.Text = "";
timer.stop();
}
当这里清空时,会不会导致timer死锁
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); } private void Form1_Load(object sender, EventArgs e)
{ } private void timer1_Tick(object sender, EventArgs e)
{
textBox1.Text = "";
timer1.Stop();
} private void textBox1_TextChanged(object sender, EventArgs e)
{
timer1.Start(); } private void button1_Click(object sender, EventArgs e)
{
timer1.Stop();
textBox1.Text = "";
}
}
}
可以啊
public Form1()
{
InitializeComponent();
_timer = new Timer();
//_timer.Enabled = true;
_timer.Tick += new EventHandler(_timer_Tick);
_timer.Interval = 10000;
_timer.Enabled = false;
}
void _timer_Tick(object sender, EventArgs e)
{
textBox2.Text = "";
_timer.Stop();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
_timer.Start();
}没发现问题的
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); } private void Form1_Load(object sender, EventArgs e)
{ } private void timer1_Tick(object sender, EventArgs e)
{
textBox1.Text = "";
timer1.Stop();
} private void textBox1_TextChanged(object sender, EventArgs e)
{
timer1.Start(); }
}
}
完全可以啊??????????????
{
textBox1.Text = "";
timer1.Stop();
} private void textBox1_TextChanged(object sender, EventArgs e)
{
timer1.Start(); }
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 1000;
aTimer.Enabled = true;
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
}
有四种System.Threading.Timer
System.Windows.Forms.Timer
System.Timers.Timer
System.Windows.Threading.DispatcherTimer
使用那个
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); } private void Form1_Load(object sender, EventArgs e)
{ } private void timer1_Tick(object sender, EventArgs e)
{
textBox1.Text = "";
timer1.Stop();
} private void textBox1_TextChanged(object sender, EventArgs e)
{
timer1.Start(); }
}
}出来吧