hi
i want my code execute always , while my program is running or while my form is opened
i use if form is already open but it work only once and don't work continuously!
like this:
/////////////////////
public void Form1_Load(object sender, EventArgs e)
{
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
//iterate through
// here is my code
}
}
/////////////////////
is it true that check it in form load?
could you help me ?
Loading
Sam HobbsPosted Aug 3, 2011, 3:22 PM
Bahar JalaliPosted Aug 3, 2011, 4:47 AM
because the command
and it execute this command on all programs.
i thinks when i put the code in a timer thick event, it can't detect "Save Az" window ! but i want when it detect a save as window then enters it.
any idea?!
Zoran HorvatPosted Aug 3, 2011, 4:14 AM
Use timer to execute code in background:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_timer = new Timer();
_timer.Interval = 1000;
_timer.Tick += new EventHandler(TimerTick);
_timer.Start();
}
void TimerTick(object sender, EventArgs e)
{
Text = DateTime.Now.ToLongTimeString();
}
private System.Windows.Forms.Timer _timer;
Your code should go into TimerTick method. This method will be executed on a UI thread so you're free to modify form's contents at will. Timer will execute once every second. You can change this interval by modifying the line:
_timer.Interval = 1000;
Interval is measured in milliseconds.
Zoran