Form1 closes after ShowDialog for Form2

855 views Asked by At

I have 2 forms. I'm opening form2 with ShowDialog(), but then when I close it (by hiding it) form 1 disappears for few seconds, but if I use show to open form 2 then this does not happen.

I need to use ShowDialog(), how could I fix disappearance of form 1 after form 2 closes ?

I tried to use Form1.Show() right after I close form 2 with Hide() but does not work.

Form1

private void p0_igra2_Click(object sender, EventArgs e) 
    {
        this.CenterToScreen();
        imevislice.ShowDialog();
    }

Form2

private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text == "")  
            errorProvider1.SetError(textBox1, "Polje more biti izpolnjeno"); 
        else  
        {
            errorProvider1.Clear();   
            ime = textBox1.Text;  
            if (radioButton1.Checked)  
                izbrane_besede = "SLO";   
            else
                izbrane_besede = "ENG";
            this.Hide();
            form1.Show();
            form1.namehangman(); 
        }
    }
1

There are 1 answers

8
BradleyDotNET On BEST ANSWER

If you open a form with ShowDialog you need to close (Form.Close) it when you are done. ShowDialog starts a modal dialog; which means the calling function will not continue execution until the form is closed.

Using Show can fix this, but you didn't say what wasn't working with that approach.

In general, ShowDialog is pretty cheap; you should be able to just close the form correctly and you won't run into any issues.