How to Use The Form Opened When Using ShowDialog()?

133 views Asked by At

Currently I am working with the ShowDialog() method and trying to figure out how it is supposed to work. I have a form, testDialog, that has a text box that will take an input string. I followed the code on the MSDN page as follows:

string Range;
testDialog specRange = new testDialog();
if (specRange.ShowDialog(this) == DialogResult.OK)
{
    Range = specRange.txtPageRange.Text;
}
else
{
    Range = "";
}
specRange.Dispose();

The thing I can't find any information on and that I can't figure out is, how do I enter the text and get it to submit? I put buttons on the form but they didn't show up when I ran the program. I enter the text into the text box but I can't hit enter or anything, my only option is to close the form.

Is there something I'm missing that I need to add so that I can hit enter or click an Okay button after entering the text?

1

There are 1 answers

1
fokasu On

From msdn :

The dialog box can be assigned one of the values of the DialogResult enumeration by assigning it to the DialogResult property of a Button on the form or by setting the DialogResult property of the form in code. This value is then returned by this method. You can use this return value to determine how to process the actions that occurred in the dialog box. For example, if the dialog box was closed and returned the DialogResult.Cancel value through this method, you could prevent code following the call to ShowDialog from executing.

The simplest method to do that is to add a Button "Ok" to your testDialog and change its property DialogResult to Ok. So when you click on it, it will return DialogResult.ok and you will enter your if.