c# - Closing browse dialog causes form to close
I have a form which is displayed through: ShowDialog()
.
The form doesn't have CancelButton
specified.
When I open a BrowseDialog
from the form and then close the BrowseDialog
, the form is also closed. How can I preven开发者_Go百科t this from happening?
When the "browse"-button is clicked:
browseDialog.SelectedPath = projectLocation.Text;
browseDialog.ShowDialog();
if (browseDialog.SelectedPath != "")
{
projectLocation.Text = browseDialog.SelectedPath;
}
When the "cancel"-button of the form is clicked:
Close();
I would guess that the button you use to show the BrowseDialog has its DialogResult set to something other than None.
If this is not the case, please post some code.
in your onclosing event from your browser dialog, do a check on the sender arg to see which dialog is requesting the close and if it's not the browser dlg, set e.Cancel = true
I stumbled upon this when I had a similar issue, ensure your parent form is not setting ITS dialog result, because once the event to call the modal dialog is done, the parent form will close if it's set to something other than none.
精彩评论