Timer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

i have a form that stays on the screen for 300 milliseconds and then closes.
straight after this, another form opens. that works but after that, the
second one closes. someone suggested that i should change the static void
main code which i have done and it still doesnt work. can anyone help me? if
you could, id be truly grateful!

cheers
 
yeah, sorry about that. i must have been in a hurry. i am using a timer but
my code closes both forms and i only want it to close the first one. here is
my code:

private void timer1_Tick(object sender, System.EventArgs e)
{
Form1 f = new Form1();
f.ShowDialog();
f.Dispose();
Close();
}
 
Do you need the form to be shown for each tick???

If no, try this code in your Main method.

static void Main()
{
Form1 f = new Form1();
f.Show();
Application.DoEvents(); // Refresh the form to be displayed.
System.Threading.Thread.Sleep(300); // Block the main thread for 300
ms.
f.Close();
f.Dispose(true);
// If you want, run another form with a message loop.
Application.Run(new Form2);
}

Hope this helps.

- Moty -
 
Back
Top