Dialog boxes and how to get the DialogResult return value

S

steve bull

I have built what I think should be a dialog box. It contains 4 tabbed panes for generating a range of colors. Each
tabbed pane consists of a panel with all the widgets on them including the OK and Cancel buttons. These buttons have to
be on the panels themselves so that they can create the color range from the current settings on the panel and return
the result via a delegate to the main dialog form.

The problem I have is that the OK button needs to do the extra work before exiting. So, is there a way that I can force
the return result from the dialog box to DialogResult.Ok (or Cancel) before exiting. I.e. can I just exit or return from
the dialog form with these return codes?

Or, can I still set the OK and cancel buttons on all the panels with (okBtn.DialogResult = DialogResult.OK) and still do
an OnClick callback for the button?


Thanks,

Steve
 
B

BrianGlacain

steve bull said:
I have built what I think should be a dialog box. It contains 4 tabbed
panes for generating a range of colors. Each
tabbed pane consists of a panel with all the widgets on them including the
OK and Cancel buttons. These buttons have to
be on the panels themselves so that they can create the color range from
the current settings on the panel and return
the result via a delegate to the main dialog form.

The problem I have is that the OK button needs to do the extra work before
exiting. So, is there a way that I can force
the return result from the dialog box to DialogResult.Ok (or Cancel)
before exiting. I.e. can I just exit or return from
the dialog form with these return codes?

Or, can I still set the OK and cancel buttons on all the panels with
(okBtn.DialogResult = DialogResult.OK) and still do
an OnClick callback for the button?

If I understand you correctly, you want the function that is called when the
OK button is clicked to do some processing before it closes the dialog box?
If so, remove the okBtn.DialogResult entry from the form, and manually add
it to the end of the eventhandler - something like this:

private void btnOK_Click(object sender, System.EventArgs e)
{
DoProcessing(); //This function does the extra stuff you want to do
DialogResult = DialogResult.OK;
Dispose();
}
 
S

steve bull

yes, thanks, that works. The problem was that I didn't want C# to do the handling automatically and I wasn't sure how to
get the calling form to pick up the return value DialogResult.OK.

steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top