Hiding a form and showing another when a button is clicked in a Windows Forms application

后端 未结 6 1419
遥遥无期
遥遥无期 2020-12-14 13:06

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

6条回答
  •  执念已碎
    2020-12-14 13:32

    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:

    private void button1_Click_1(object sender, EventArgs e)  
    {  
        if (richTextBox1.Text != null)  
        {  
            this.Visible=false;
            Form2 form2 = new Form2();
            form2.show();
        }  
        else MessageBox.Show("Insert Attributes First !");  
    
    }
    

    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

提交回复
热议问题