I want to display a small form when the program is ran. This is the code:
private void Form1_Load(object sender, EventArgs e)
{
this.Opacity = 0;
InitForm init = new InitForm();
init.Show();
init.BringToFront();
comm = init.Start();
this.Opacity = 100;
}
The Start() method draws some lines to the list box on the InitForm.
I have two problems:
- When the program starts, the list box is not populated, I just get
the waiting cursor, then the main form is displayed and the box is
populated at the same time; - The
InitFormis behind the main form. How do I bring it to front?
Can’t see a ListBox in that code. But painting doesn’t happen until the UI thread goes idle again, after your Load event handler completes. Which also means that the Opacity assignment doesn’t accomplish anything.
The Z-order problem is (partly) caused by this too, the main form isn’t visible yet so BringToFront() doesn’t work. Use either Show(this) so that InitForm is an owned window that always displays in front on the main form (recommended) or use the Shown event instead.