Armen Matevosyan
Armen Matevosyan

Reputation: 11

Block Form1 until Form2 closes c#

In my code i from form1 launch form2 using .Show() .

Form2 f2 = new Form2();
f2.show();

block form1 until form2 close and when form2 closed continue my code.

Upvotes: 1

Views: 1440

Answers (3)

Mohsen Shafizadeh
Mohsen Shafizadeh

Reputation: 13

I tested that ways and don't worked but only below code worked:

    private void button1_Click_1(object sender, EventArgs e)
    {
        Form2 frm = new Form2();
        this.Enabled = false;
        frm.Show();
        frm.FormClosing += new FormClosingEventHandler(frm_FormClosing);
        frm.Show();
    }

    private void frm_FormClosing(object sender, FormClosingEventArgs e)
    {
        this.Enabled = true;
    }

Upvotes: 0

squelos
squelos

Reputation: 1189

Try using

Form2 f2 = new Form2();
f2.showDialog();

Upvotes: 1

Mikatsu
Mikatsu

Reputation: 550

.Show() will show the new form you are displaying but it will enable you to go back and use the controls in the Main Form and .ShowDialog() wont allow you to access your main form unless its closed.

f2.ShowDialog();

Upvotes: 4

Related Questions