Wait for response of a method to proceed

1

I have the following problem, I'm making a popup to display information on the screen, almost the same way as a ShowDialog() , being this way:

GeneralPopUp popupErro = new GeneralPopUp("Titulo", "Mensagem");
GeneralPopUp.ACTION_TYPE at = popupErro.ShowPopUp(parent);

And my intention is to wait for his action inside the popup that is a Form to then validate what was done as follows:

switch (at)
                {
                    case GeneralPopUp.ACTION_TYPE.NULO:
                        break;
                    case GeneralPopUp.ACTION_TYPE.OK:
                        break;
                    case GeneralPopUp.ACTION_TYPE.FECHAR:
                        break;
                    case GeneralPopUp.ACTION_TYPE.EXTRA1:
                        break;
                    case GeneralPopUp.ACTION_TYPE.EXTRA2:
                        break;
                    default:
                        break;
                }

But the way I'm doing, it does not wait for the actions to take place inside that form and then to get on my switch, I'll probably have to do a handler for that situation.

What's the best way to do this handler ? If not, what is another solution?

    
asked by anonymous 19.08.2014 / 15:38

1 answer

1

The ideal would be to display the popup as a modal dialog. If this is not possible because of some logic you need specific to the ShowPopUp method of this class, the way is to appeal.

Lock the parent form (disable it without fear!). Also prevent the form from closing, by canceling the event FormClosing in the field if necessary ( Closing is obsolete).

That's just a matter of treating the same event in the popup. When it is being closed, check the state of its controls and apply its logic. This is even a good programming practice.

The FormClosing event passes a parameter of type FormClosingEventArgs ". This class has an interesting property. Cancel allows you to cancel the closing of a form, simply put its value as false within the method that handles the event. So if the logic does not validate something you can prevent the popup from closing easily.

Edit: Seeing that your GeneralPopUp is Form , just run the switch within the event I describe above. This way, whether the form was opened via Show or ShowDialog . Opening as a dialog you do not have to make any effort to block the parent form. Good luck there!

    
19.08.2014 / 15:56