设置起始位置为打开文件对话框/ SaveFileDialog [英] Setting the start position for OpenFileDialog/SaveFileDialog

查看:1588
本文介绍了设置起始位置为打开文件对话框/ SaveFileDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关在WinForm应用程序,我可以设置其大小和位置之前,我与它显示的任何自定义对话框(表格):

For any custom dialog (form) in a WinForm application I can set its size and position before I display it with:

form.StartPosition = FormStartPosition.Manual;
form.DesktopBounds = MyWindowPosition;



与多个显示器时,这是特别重要的。如果没有这样的代码,当你从你已经拖动到第二个显示器应用程序中打开一个对话框,将出现在主显示器上的对话。这带来糟糕的用户体验。

This is particularly important when dealing with multiple monitors. Without such code, when you open a dialog from an application that you have dragged to a second monitor, the dialog appears on the primary monitor. This presents a poor user experience.

如果有任何挂钩,设置了标准的.NET的OpenFileDialog和SaveFileDialog的位置(不具有财产中StartPosition我想知道。)

I am wondering if there are any hooks to set the position for the standard .NET OpenFileDialog and SaveFileDialog (which do not have a StartPosition property).

推荐答案

我怀疑你能做的最好的就是确保你使用的 的ShowDialog 的超负荷接受一个 IWin32Window 来为父使用。这的可能的帮助它选择一个合适的位置;最常见的:使用

I suspect that the best you can do is make sure you use the overload of ShowDialog that accepts an IWin32Window to use as the parent. This might help it choose an appropriate location; most commonly:

using(var dlg = new OpenFileDialog()) {
    .... setup
    if(dlg.ShowDialog(this) == DialogResult.OK) {
        .... use
    }
}

这篇关于设置起始位置为打开文件对话框/ SaveFileDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆