Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom dialog box in C#?

I have a button that when clicked, a dialog box opens up with various controls on it such as radio buttons and text boxes. If OK then the values in that dialog box is passed back to the button and the rest of the code is processed with those values. If Cancel then do nothing.

How can I do this? I was thinking of making another form with those controls and have that button call the new form but I want the rest of the controls to stop until the form is completed like a dialog box.

like image 499
Jack Avatar asked Aug 02 '11 09:08

Jack


2 Answers

1.) Create the form you were talking about with all of the neccessary UI elements. Also add an OK and Cancel button to it.

2.) In the property pane for the OK and Cancel button, set the DialogResult values to OK and Cancel, respectively. Additionally, you can also set the Form's CancelButton property to be that of the Cancel button you've created.

3.) Add additional properties to the dialog that correspond to the values you'd like to return.

4.) To display the dialog, do something along the lines of

using( MyDialog dialog = new MyDialog() )
{
   DialogResult result = dialog.ShowDialog();

   switch (result)
   {
    // put in how you want the various results to be handled
    // if ok, then something like var x = dialog.MyX;
   }

}
like image 64
dotnetnate Avatar answered Sep 30 '22 10:09

dotnetnate


You can do this. Create a new form. From your main form you can call custom form using:

CustomForm customForm = new CustomForm();
customForm.ShowDialog(); 

Make sure that you add relevant button to custom form and set their DialogResult property to OK, Cancel or anything else.

like image 25
Husein Roncevic Avatar answered Sep 30 '22 10:09

Husein Roncevic