在另一个自定义对话框之上保存对话框的行为很奇怪!

发布于 2024-08-27 10:30:00 字数 936 浏览 9 评论 0原文

我的应用程序中有图表另存为图像功能。图表控件是一个自定义用户控件,其中包含自定义逻辑。它还具有一些基于大小、缩放等的缩放功能。但是,在将它们保存为图像时,我想为用户提供设置图像大小的选项(例如:800x600 px @ 300 DPI)。

为此,我创建了一个带有文本框/复选框等的表单,用于图像的各种设置。这些文本框之一用于文件名。文件名文本框是只读的,并带有一个浏览按钮,单击时会显示一个 SaveFileDialog。

用户单击主窗体菜单中的“另存为图像”。我使用下面的代码显示 ImageExportDialog:

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

在 ImageExportDialog 中,用户单击浏览按钮,SaveFileDialog 显示如下:

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

现在的问题是,当用户单击 SaveFileDialog 中的“保存”按钮时,如预期的 txtFileName .Text 已设置,但父自定义对话框似乎也从 ShowDialog 方法返回,并且 DialogResult 与 SaveFileDialog 的结果相同!然后该控件继续执行上面代码的“获取用户选择的设置并生成图像”部分。

不太确定我在这里做错了什么!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁虫ゝ 2024-09-03 10:30:01

啊啊!!!

我自己发现了这个问题。我复制粘贴了 ImageExportDialog 的“确定”按钮来为 SaveFileDialog 创建“浏览”按钮。

你猜怎么着,浏览按钮的 DialogResult 属性设置为“确定”!将其更改为“无”解决了该问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文