Expect response from a method to proceed

Asked

Viewed 728 times

1

I have the following problem, I am doing a popup to display on the screen information, almost in the same way as a ShowDialog(), being so:

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 which is a Form and 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, it doesn’t wait for the actions to occur inside this form and then enter my switch, I’ll probably have to make an Handler for this situation.

What is the best way to do this Handler? If not, what is another solution?

1 answer

1


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

Block the parent form (disable it without fear!). Also prevent the form from being closed by canceling the event FormClosing in the box if necessary (the Closing is obsolete).

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

The event FormClosing gives you a type parameter FormClosingEventArgs. This class has an interesting property. Cancel allows you to cancel the closing of a form, just put its value as false within the method that treats the event. Hence if logic does not validate something you can prevent the popup from being closed easily.

Edit: seeing that his GeneralPopUp is a Form, just run the switch inside the event I describe above. This way, it does not matter if the form was opened via Show or ShowDialog. Opening as a dialog you don’t even have to work hard to block the parent form. Good luck there!

  • I made her, she’s mine.

  • but this way I can make my code wait for the answer of this popup to continue?

  • Yes. If the popup is opened as a dialog, the control will only return to the parent form when the dialog is closed. And before being closed, it necessarily triggers the event FormClosing. Remember: you will treat the event FormClosing from the popup form, not from the parent.

  • excellent!!!!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.