I am using C # 2.0 and working on Winforms. I have two applications (app1, app2). when starting application 1, it automatically calls application2. I have a timer in my application2, and in timer_tick I fire the buttonclick event. But I want this button to be pressed only once when the application is running.
The problem I ran into is some unknown reason why the timer starts more than once, although I do mytimer.Enable = false. Is there a way when I can make the timer not get called a second time. OR Is there a way I can make the click event of a button automatically without using timers.
Here is the code:
private void Form1_Activated(object sender, EventArgs e) { mytimer.Interval = 2000; mytimer.Enabled = true; mytimer.Tick += new System.EventHandler(timer1_Tick); } private void timer1_Tick(object sender, EventArgs e) { mytimer.Enabled = false; button1_Click(this, EventArgs.Empty); } private void button1_Click(object sender, EventArgs e) { }
source share