Link to home
Start Free TrialLog in
Avatar of muffintwinkly
muffintwinkly

asked on

the use of DialogResult question.

Hi,
can you please explain the use of DialogResult in this code?  I have two forms.  Form1 opens Form2 as a modal dialog using a button.  For that action, I used f2.ShowDialog(); when 'open' button is clicked on Form1.  
Now, in Form2 when I click 'Save' button, the values in Form2 will be saved.

private void button1_Click(object sender, EventArgs e)
{
            // Do somthing for saving result.        
            this.DialogResult = DialogResult.OK;            
 }

But, when I add the last line(this.DialogResult = DialogResult.OK; ), Form2 is closed.  I don't understand the last line of code.  I don't know how this line of code close Form2.  What does 'DialogResult.OK' really mean in this code?  
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi muffintwinkly;

You can use this property to determine how a dialog box is closed in order to  properly process the actions performed in the dialog box by the caller.

Form.DialogResult Property can be found here.
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.dialogresult.aspx

Possible values for DialogResult and there meaning can be found here
http://msdn.microsoft.com/en-us/library/system.windows.forms.dialogresult.aspx

Fernando
Setting the Form.DialogResult Property to anything other then DialogResult.None will hide the form after executing the command.
Avatar of muffintwinkly
muffintwinkly

ASKER

Thanks, it helped me alot already.  But, I want to know what know is what 'DialogResult.Ok' means.  I read MSDN, but still don't understand what 'The dialog box return value is OK ' means. - I know that this value is from Form2.  but, does it mean 'Form2 is opened correctly?' or something else?  I guee that 'this.DialogResult' means Form2's DialogResult.  What is 'DialogResult.OK' and why do whe this value to Form2's DialogResult?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much!