Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

close-open 1

Status
Not open for further replies.

Pumzy

Programmer
Nov 20, 2003
13
JP
Hi peeps! I am having a problem with closing and opening a form using my timer.

I have a timer in one of my forms (frmFlash) which after 2 seconds should close the form and open another (frmMain). The problem is, after the timer closes frmFlash, frmMain does not open.
But if I display a message box during frmMain's Load procedure there is no problem and the form (frmmain) I want to show opens.

I guess I need a lil tip from you guys!.
tnx

KDjLogan
 
Hi,

I'm not sure at what moment you're trying to run this, but the controlling program needs to be in the same scope.

For instance:

If you were trying to display a splash screen, you would write the following:

[tt]
[STAThread]
static void Main()
{
Form1 frm = new Form1();
frm.ShowDialog();
Application.Run(new Form2());
}
[/tt]

Execution of this code will now halt until Form1 is closed.

The timer is in Form1. On the Tick event, you would call this event method:
[tt]
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
this.Close();
}
[/tt]
which would close Form1 and allow the Application.Run to execute.

If you were not doing this is the startup, just omit the Application.Run and instantiate the Form2 and call the .Show method.

I hope this was helpful.

Cheers!
 
thanks a lot snowmaster! big help for a newbie like me...
happy holidays to you! :)

KDjLogan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top