By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

timer click button every X time

P: n/a

how i can set that the timer will press the button every X time
automatically on my form with VS 2005, what is the code for that?

Jun 29 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
In abbreviated (inline delegates) syntax (for brevity), something like
below; although personally I would be inclined to simply execute the method
underlying the button-click event-handler directly - after all, what purpose
is the button serving here?

Anyway, the following works (Timer is the System.Windows.Forms one, not the
System.Timers one):

static void Main() {
using (Form f = new Form())
using (Timer t = new Timer())
using (Button b = new Button()) {
b.Click += delegate { Debug.WriteLine("Clicked"); };
t.Tick += delegate { b.PerformClick(); };
t.Interval = 1000;
f.Load += delegate { t.Start(); };
Jun 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.