Save Dialog on top of another custom dialog is behaving strangely!

Posted by Raghu on Stack Overflow See other posts from Stack Overflow or by Raghu
Published on 2010-04-04T09:02:38Z Indexed on 2010/04/04 9:13 UTC
Read the original article Hit count: 300

Filed under:
|
|
|

I have a save as image feature for charts in my application. The chart control is a custom user control with custom logic in them. It also has some scaling based on size, zoom etc. However, while saving them as an image I would like to give the user the option to set the size of the image (eg: 800x600 px @ 300 DPI).

To do this I have created a Form with textboxes/checkboxes etc for various settings for image. One of these TextBoxes is for the file name. The file name textbox is readonly and is accompanied with a browse button which shows a SaveFileDialog when clicked.

The user clicks "Save As Image" in the main form's menu. I show the ImageExportDialog using the code below:

using(ImageExportDialog dlg = new ImageExportDialog())
{
   if(dlg.ShowDialog() == DialogResult.OK)
   {
      //get the settings selected by the user and generate the image
   }
}

In the ImageExportDialog, the user clicks on the browse button and the SaveFileDialog is shown as follows:

using(SaveFileDialog dlg = new SaveFileDialog())
{
   if(dlg.ShowDialog() == DialogResult.OK)
   {
      txtFileName.Text = dlg.FileName;
   }
}

Now the problem is, when the user clicks on "Save" button in the SaveFileDialog, as expected the txtFileName.Text is set, but the parent custom dialog also seems to return from the ShowDialog method and the DialogResult is the same as the one for SaveFileDialog! The control then goes on to the "get the settings selected by the user and generate the image" part of the code above.

Not really sure what I am doing wrong here!

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms