The concept of the screen saver does not affect me as something complicated, but I am having problems so that the entire screen saver is painted.
Say I have two System.Windows.Forms.Form s: RealForm and SplashScreen. RealForm contains an initial graphical interface. During the RealForm loading process (that is, in the event handler for the Load event), RealForm creates a database connection and then checks the connection. This may take a few seconds, so before I do all this, I will try to set the splash screen like this:
private void RealForm_Load(object sender, EventArgs e) { SplashScreen splash = new SplashScreen(); splash.Show(); loadAndCheckDatabase(); splash.Close(); }
The problem is that the splash screen is only partially rendered, and therefore it does not look like a large screen. Any idea why? What should I do?
For bonus points, does anyone know where to find an explanation for all the series of events that occur during the typical creation, use and destruction of forms? The above problem is probably due to the fact that I do not understand what is happening in the order of things or where you can connect to form events.
UPDATE Close, but not quite: look for a bit more advice. Here's the current code:
private SplashScreen splash = new SplashScreen(); private void RealForm_Load(object sender, EventArgs e) { splash.Show(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler (worker_RunWorkerCompleted); worker.RunWorkerAsync(); this.Visible = false; } void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { splash.Close(); this.Visible = true; } void worker_DoWork(object sender, DoWorkEventArgs e) { loadAndCheckDatabase(); }
Unfortunately, this.Visible = false does nothing, because it is automatically set to true in code that I do not control. So, to get around this, I put this.Visible = false in the handler for the Shown form Shown . However, as you can probably guess, you can still see the shape for a split second ... so this is not a very good solution.
Is there a way to wait for the workflow while I'm still in the load handler?