How to make a YesNo panel that works like ShowDialog()

htn5ca
htn5ca used Ask the Experts™
on
I want to make a function that will build a Yes or No question panel (just like MessageBox.show but in a panel and not a new window).  The problem I am having is I cannot make the program stop execution and wait for the user input for the question.  Another example is OpenFileDialog.ShowDialog() will wait for the user input before moving on to the next line.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I can not understand your problem ?

What you want ?

You want to display yes / no box in panel and program continues to execution ?

or

You want to display yes / no panel and program can not wait for execution .


You can do this with panel or form .

If you using form then instead of showdialog use Show methos form display and program continues to execution.


Commented:
You need to use Form.ShowDialog() to achieve it.
But you need to modify your Form a bit so that it appears like a panel.

This what you have to do.

Derive a class(Say QuestionForm) from Form and set its FormBorderStyle to None. This will make the Form appear without a titlebar.

Add the Yes/No buttons on this form.
Set the Yes Button's DialogResult property to OK
and the No Button's DialogResult property to Cancel

In your main application form, reserve some space in order to place the QuestionForm there. Get the top left location of that space (say X,Y)
When you want to display the QuestionForm in your main application, do the following:
Create an instance of the QuestionForm. (QuestionForm qForm = new QuestionForm(); )
Set its location. (qForm.Location = this.PointToScreen(X,Y).
Call the ShowDialog method. (qForm.ShowDialog());

Now until the user clicks the Yes/No button, the QuestionForm will be visible and the user will not be able to interact with the MainApplication.

Once the user clicks either Yes or No then the Main Application will be active again.

Author

Commented:
This is good enough even though I would have rather made my own ShowDialog() if possible but this is a good work around

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial