22

我很好奇,它可以为我的小应用程序画龙点睛。谢谢!

4

4 回答 4

29

如果您直接使用类 FolderBrowserDialog 则不能。但我在某处读到,可以使用 P/Invoke 更改标题并发送 WM_SETTEXT 消息。

在我看来,这不值得痛苦。只需使用属性描述添加信息:

FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.Description = "Select the document folder";
于 2009-08-19T02:40:24.090 回答
3

简单的答案是你不能。该对话框使用 Windows 上文件夹浏览器样式对话框的标准标题显示。最好的选择是通过设置 Description 属性来确保您有有意义的描述性文本。

即使您要使用 P/Invoke 直接调用SHBrowseForFolder Win32 API 函数,唯一的选择仍然无法更改对话框的实际标题。可以设置BROWSEINFO结构的 lpszTitle 字段,即

指向显示在对话框中树视图控件上方的以 null 结尾的字符串的指针。该字符串可用于向用户指定指令。

于 2009-08-19T03:08:00.627 回答
0

您可以使用以下方法更改它:

SetWindowText (hwnd, "Select a Folder");

hwnd触发浏览文件夹对话框的窗口句柄在哪里。

于 2019-04-23T02:46:00.263 回答
-1

我正在寻找如何做到这一点,但在很大程度上必须自己弄清楚。我希望这可以节省一些时间:

在我的主要方法之上,我放了:

    [DllImport("user32.dll", EntryPoint = "SetWindowText", CharSet = CharSet.Ansi)]
    public static extern bool SetWindowText(IntPtr hWnd, String strNewWindowName);
    [DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Ansi)]
    public static extern IntPtr FindWindow(string className, string windowName);

因为我知道在显示对话框时线程会暂停,所以我创建了一个新线程来检查该对话框窗口是否存在。像这样:

    bool notfound = true;
    new Thread(() => { 
    while (notfound)
    {
        //looks for a window with the title: "Browse For Folder"
        IntPtr ptr = FindWindow(null, "Browse For Folder");
        if (ptr != IntPtr.Zero)
        {
            //tells the while loop to stop checking
            notfound = false;
            //changes the title
            SetWindowText(ptr, "Be happy!");
        }
    }
    }).Start();

然后,我启动对话框:

    using (var fbd = new FolderBrowserDialog())
    {
        DialogResult result = fbd.ShowDialog();
        if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
        {
            //do stuff
        }
    }

这对我有用,而且并不复杂。希望这可以帮助任何可能偶然发现此页面的人。顺便说一句,请记住线程必须在对话框窗口启动之前启动,以便它可以运行并在窗口存在时立即检查。

于 2019-06-25T05:19:32.620 回答