Reputation: 27633
I thought the Load event might help, but the following code just shows “Done” immediately.
public Form1()
{
InitializeComponent();
Load += new EventHandler(Form1_Load);
}
void Form1_Load(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
Text = "Done";
}
How do I make it Sleep after the form is shown?
Thanks.
Upvotes: 11
Views: 40895
Reputation: 112259
Thread.Sleep(3000); in the Load event handler delays the form opening for 3 seconds. This why it does not work as you expect. A timer is the best solution.
Upvotes: 0
Reputation: 62248
I would suggest do not block a form, process something and after show in its title "Done", cause that what you want to do, I presume. This gives to the user blocked UI feeling, which is not good.
It's definitely better to show some temporary "Wait for..." form and on completion of the operation/calculation you perform, show your main form.
Much more UX focused design.
Upvotes: 3
Reputation: 3451
There is a Shown event for a windows form. Check out: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.shown.aspx
Or if you are lazy, here you go:
public Form1()
{
InitializeComponent();
Shown += Form1_Shown;
}
private void Form1_Shown(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
Text = "Done";
}
Enjoy.
Upvotes: 27