Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6552733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:29:46+00:00 2026-05-25T12:29:46+00:00

I want different timer with different interval that i input.For example, if I input

  • 0

I want different timer with different interval that i input.For example, if I input 4, 4 timer create and show time in 4 label, where 1st timer’s time change in 1sec,2nd timer’s time change in 2sec,3rd timer’s time change in 3sec and 4tn timer’s time change in 4sec.Here is my code,

        string input = textBox2.Text;
        int n = Convert.ToInt32(input);
        for (i = 1; i <= n; i++)
        {

            Timer timer = new Timer();
            timer.Tick += new EventHandler(timer_Tick); 
            timer.Interval = (1000) * (i);              


            timer.Enabled = true;                      
            timer.Start();                            



            Label label = new Label();               
            label.Name = "label"+i;
            label.Location = new Point(100, 100 + i * 30);
            label.TabIndex = i;
            label.Visible = true;


            this.Controls.Add(label);

        }
     private void timer_Tick(object sender, EventArgs e)
        {

             label.Text = DateTime.Now.ToString();


         }

But i don’t get any output.What can i do.I use windows application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:29:47+00:00Added an answer on May 25, 2026 at 12:29 pm

    The other way, than Bala R shown to you is keep reference of variable in a dictionary (dict) for timer and label pairs, and access in event handler by sender reference (Full source code, with 2 text boxes ans a button, 2nd textbox contains text “3”), hope it will help:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ProjectDocumentationWorkspace.UI
    {
        public partial class MainForm : Form
        {
            private Dictionary<Timer, Label> dict = new Dictionary<Timer, Label>();
    
            public MainForm()
            {
                InitializeComponent();
            }
    
            private void CreateTimers()
            {
                string input = textBox2.Text;
                int n = Convert.ToInt32(input);
                for (int i = 1; i <= n; i++)
                {
    
                    Timer timer = new Timer();
                    timer.Tick += new EventHandler(timer_Tick);
                    timer.Interval = (1000) * (i);
    
                    Label label = new Label();
                    label.Name = "label" + i;
                    label.Location = new Point(100, 100 + i * 30);
                    label.TabIndex = i;
                    label.Visible = true;
    
                    this.Controls.Add(label);
    
                    dict[timer] = label;
    
                    timer.Enabled = true;
                    timer.Start();
                }
            }
    
            private void timer_Tick(object sender, EventArgs e)
            {
                Timer t = (Timer)sender;
                DateTime current = DateTime.Now;
                dict[t].Text = string.Format("{0:00}:{1:00}:{2:00}", current.Hour, current.Minute, current.Second);
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                CreateTimers();
            } 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a view that has different displays according to the role
I want to show text one after the other on certain interval of time
Every time that I want to do a Layout, I'm getting a black layout
I want to create 3 random number at a time (simultaneously). However, they returned
I want to query a number of different databases mainly Oracle and Informix. Can
We want to maintain 3 webservices for the different steps of deployment, but how
I want to gather data from different data servers located in Europe and Asia.
I want my emacs buffer to have a different name than the file name.
I want to determine whether two different child nodes within an XML document are
I want to see all the different ways you can come up with, for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.