I want it to execute the first part of the code, then make the pictureBox visible, pause for 3 seconds, hide the pictureBox and execute the rest of the code:
// first part of the code here
pb_elvisSherlock.Visible = true;
Thread.Sleep(300);
pb_elvisSherlock.Visible = false;
// rest of the code here
But it executes the whole block of code and only then pauses. Any ideas what to do?
Thanks!
The problem is that you don’t give the message loop a chance to display the picture box before you pause the GUI thread.
Application.DoEvents()solve that.Note that using
Thread.Sleepon the GUI thread will make the painting freeze (try move a window over your app when theSleepis active).You should do something like this:
It’s still kind of a hack but the window will be redrawn and respond as it should.
Update 2
Well.
DoEventsseems to be a bit to much of a hack. (thanks for the comments).If the picturebox is a kind of a nag screen do something like this:
Alternative 1
Closeafter three secondsThat solution prevents your users from doing anything in your “normal” form while the nagform is visible.
Alternative 2