gpt4 book ai didi

c# - FolderBrowserDialog - 发生 Win32Exception - 参数不正确

转载 作者:太空狗 更新时间:2023-10-29 17:51:17 25 4
gpt4 key购买 nike

我尝试像这样使用 WPF 中的 FolderBrowserDialog:

public static bool BrowseFolder(out string folderName)
{
using (System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog())
{
var result = dlg.ShowDialog();
folderName = dlg.SelectedPath;
return result == System.Windows.Forms.DialogResult.OK;
}
}

在 Visual Studio 2010 中使用“异常中断”时,在 ShowDialog() 调用中关闭对话框后出现异常。我很好奇为什么会这样。

异常:Win32Exception
消息:参数不正确
堆栈跟踪:在 MS.Win32.UnsafeNativeMethods.SetFocus(HandleRef hWnd)

更新
我还尝试显式设置父级,但仍然抛出了异常。

var w = new System.Windows.Interop.WindowInteropHelper(parent);
System.Windows.Forms.IWin32Window i = new WindowWrapper(w.Handle);
result = dlg.ShowDialog(i);

最佳答案

这只是一些互操作性问题。当对话框关闭时,WPF 代码尝试将焦点设置回主窗口。问题是,对话框已禁用窗口,因此它还不能接收焦点。 WPF 太急于改变焦点,并且对对话框行为一无所知。实际上没有任何问题。

关于c# - FolderBrowserDialog - 发生 Win32Exception - 参数不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3438985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com