I have this line working, before I needed to add a feature:
public MainForm()
{
InitializeComponent();
refreshUI();
}
then I needed to show a welcomeBox for some seconds before showing the MainForm. so I’ve changed the code like this:
System.Threading.Timer timer;
GUI.WelcomeBox welcomeBox;
public MainForm()
{
this.Visible = false;
//Showing welcome box
welcomeBox = new GUI.WelcomeBox();
welcomeBox.Visible = true;
this.Visible = false;
timer = new System.Threading.Timer(new System.Threading.TimerCallback(delayedActions),null,5000,2000);
}
private void delayedActions(object o)
{
welcomeBox.Visible = false;
welcomeBox.Close();
timer.Dispose();
InitializeComponent();
// this line is unreachable, because of error
refreshUI();
}
but an error occurred at InitializeComponent(): Problem Event Name: CLR20r3
Problem Signature 01: todoweeklyshedule.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 4fc5385b
Problem Signature 04: System.Windows.Forms
Problem Signature 05: 4.0.0.0
Problem Signature 06: 4ba1e14e
Problem Signature 07: a11
Problem Signature 08: 1b
Problem Signature 09: System.ArgumentException
OS Version: 6.1.7601.2.1.0.768.3
Locale ID: 1033
Additional Information 1: a1ee
Additional Information 2: a1ee2874cedcaa72f2a8419ddd18697e
Additional Information 3: a319
Additional Information 4: a319510eabcccf7de47b58017b885ff3
by the way, the MainForm will be shown even with the this.Visible = false; line. I have called the MainForm() with Application.Run(new MainForm()); is this the reason?
Can’t set visible until InitialiseComponents is called, you could probably hack away at this but your real problem is your code is in the wrong place.
Move it all in to program.cs, and call it before Application.Run(new MainForm());
If it were me I’d move the timer on to the welcomebox, get the eventhandler to close it and show it modally as well.
Well actually that’s not true, if it were me I wouldn’t do this, because I know it would annoy the heck out of any user of the application.