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

后端 未结 6 1421
遥遥无期
遥遥无期 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:35

    Anything after Application.Run( ) will only be executed when the main form closes.

    What you could do is handle the VisibleChanged event as follows:

    static Form1 form1;
    static Form2 form2;
    
    static void Main()
    {
    
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        form2 = new Form2();
        form1 = new Form1();
        form2.Hide();
        form1.VisibleChanged += OnForm1Changed;
        Application.Run(form1);
    
    }
    
    static void OnForm1Changed( object sender, EventArgs args )
    {
        if ( !form1.Visible )
        {
            form2.Show( );
        }
    }
    

提交回复
热议问题