views:

83

answers:

1

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!

A: 

Arghhh!!!

Found out the issue myself. I had copy-pasted the OK button of the ImageExportDialog to create the Browse button for the SaveFileDialog.

Guess what, the Browse button had it's DialogResult property set to "OK"! Changing it to "None" solved the issue.

Raghu
Mark this as the answer! :)
Oskar Kjellin