该控件的启动与关闭分别是.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;请高手指点希望能给出具体代码

解决方案 »

  1.   

    可以再加一个Timer (用来监视TextBox的值是否为空),用来控制第一个Timer
      

  2.   

     private void timer1_Tick(object sender, EventArgs e)
            {
            
            }这个你没有用上吗?
      

  3.   

    button_click() 

      textBox.Text = ""; 
      timer.stop(); 

    当这里清空时,会不会导致timer死锁
      

  4.   

    timer.Enable=true; 开启timer控件;timer。Enable=false;timer控件失效
      

  5.   


    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 = "";
            }
        }
    }
    可以啊
      

  6.   

    private Timer _timer;
            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();
            }没发现问题的
      

  7.   

    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();        }       
        }
    }
    完全可以啊??????????????
      

  8.   

     private void timer1_Tick(object sender, EventArgs e) 
            { 
                textBox1.Text = ""; 
                timer1.Stop(); 
            }         private void textBox1_TextChanged(object sender, EventArgs e) 
            { 
                timer1.Start();         } 
      

  9.   

     System.Timers.Timer aTimer = new System.Timers.Timer();   
      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
    使用那个
      

  10.   


    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();        }       
        }
    }出来吧
      

  11.   

    控制TIMER运行还是停止,就是timer.Enabled =true or false;STOP同样是靠这种方式控制TIMER的