Timer component



  • Tell me, there's a Timer component in the VS, and that's where he has one event. Timer1_TickSo I didn't quite understand when it worked?

    And the second question, the Interval field, I didn't quite understand how to fill it properly... ..injecting 1,000 - it works every second, injecting 10000 - only works once... ♪



  • Development related to Timer_tick will be performed once at intervals. Interval is counted in milliseconds. (i.e. interval=1000 is 1 second)

    It's actually msdn. http://msdn.microsoft.com/ru-ru/library/system.windows.forms.timer.tick.aspx#Y0 ♪

    Operating code:

    using System;
    using System.Windows.Forms;
    

    namespace TimerTest
    {
    public partial class Form1 : Form
    {
    private int timer = 0;
    private bool flag=false;

    public Form1()
    {
        InitializeComponent();
    }
    
    private void timer1_Tick(object sender, EventArgs e)
    {
        timer++;
        lTimer.Text = timer.ToString();
    }
    
    private void bStart_Click(object sender, EventArgs e)
    {
        if (flag == false)
        {
            flag = true;
            timer1.Enabled = true;
            timer1.Start();
            timer++;
        }
            else
            {
            timer1.Stop();
            timer1.Enabled= false;
            flag = false;
            }
        }
    

    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2