Reactivate form when closing another

0

I have a main form and this way I click on a button and open another form , then when I open this other form I deactivate the main, until then everything well, then I wanted it when the user closed the second form , the main would resume working normally. I would like to do this using the event FormClosed in the second form , so how will I re-enable the first form in the second code?

This is the part of the code that opens the form

if (numbersandletter->IsMatch(txta->Text) && (Convert::ToDouble(a) * letra) > 0){

                Mat::Mat1^ mat1 = gcnew Mat1();
                mat1->Show();
                this->Enabled = false;

    }

I open the secondary form and disable the parent.

    
asked by anonymous 05.11.2014 / 23:46

2 answers

1

Try this code:

if (numbersandletter->IsMatch(txta->Text) && (Convert::ToDouble(a) * letra) > 0){
            Mat::Mat1^ mat1 = gcnew Mat1();
            this->Enabled = false;  // Desnecessário
            mat1->ShowDialog(this); // O ShowDialog ficara aguardando o fechamento do form
            this->Enabled = true;   // Esta linha será executada após o fechamento do form
            this->Focus();       

}
    
06.11.2014 / 01:57
1

You can do the same code in the secondary form, but I do not think you can do it directly in formClosed, but in FormClosing, because this event is fired before the form closes.

The difference from one code to another is that instead of using

mat1->show();
this->Enabled = False;

You would have to use a command like:

form1->show();
form1->Enabled = True;
this->Enabled = False;

Following the opening and activating sequence of the forms.

Another way, which would involve a little more work, is to create a global variables "Register" indicating status, a global array [form, status] to be checked at each form beginning, where only the forms would change the value of the respective "Form".

In any case, I believe both solutions are valid.

    
06.11.2014 / 01:56