I am doing an application a Windows Form application. At first, a certain form appears, and after the user hits the next button, this form should be hidden and another form is shown.
I tried to do it. I managed to hide the current form, but the next one won’t show.
Here is my attempt:
This is the button’s event handler
private void button1_Click_1(object sender, EventArgs e)
{
if (richTextBox1.Text != null)
{
this.Visible=false;
}
else
MessageBox.Show("Insert Attributes First !");
}
This is the main function:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form2 form2 = new Form2();
Form1 form1 = new Form1();
form2.Hide();
Application.Run(form1);
while (true)
{
if (form1.Visible == false)
form2.Show();
}
}
The While statement will not execute until after form1 is closed – as it is outside the main message loop.
Remove it and change the first bit of code to:
This is not the best way to achieve what you are looking to do though. Instead consider the Wizard design pattern.
Alternatively you could implement a custom ApplicationContext that handles the lifetime of both forms. An example to implement a splash screen is here, which should set you on the right path.
http://www.codeproject.com/KB/cs/applicationcontextsplash.aspx?display=Print