我有一个FolderBrowserDialog
,我希望(在标题中)显示文字"选择目标文件夹"而不是"浏览文件夹"。
我知道我可以使用以下方式自定义说明:
folderDlg.Description = "Select destination folder"
但这将是一个权宜之计的解决方案(如果我找不到办法去做我想做的事)。
我也看到了here给出的答案,用于自定义FolderBrowserDialog
,但我不准备这样做。
有更简单的方法吗?
答案 0 :(得分:0)
在任何模块中声明这些API
Public Declare Auto Function FindWindow Lib "user32" _
(ByVal ClassName As String, ByVal WindowTitle As String) As IntPtr
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" _
(ByVal hwnd As IntPtr, ByVal lpString As String) As Long
假设我们在名为mainForm的表单中有一个名为folderDialog的FolderBrowserDialog
添加此In模块/类,其中Sub显示对话框
Imports System.Threading
在显示对话框的子栏中使用此代码
...
Dim thr As New Thread(
Sub()
Dim bNoWind As Boolean = True
Dim iPtr As IntPtr
While bNoWind
iPtr = FindWindow(Nothing, "Browse For Folder")
If iPtr <> IntPtr.Zero Then
bNoWind = False
SetWindowText(iPtr, "My Folder Browser Title")
End If
End While
End Sub
)
thr.Start()
mainForm.folderDialog.ShowDialog()
...
这个想法是在显示对话框之前启动一个新线程,因为显示对话框会暂停,直到按下“确定”或“取消”为止。新的踏板开始搜索具有默认标题的窗口。当显示时,它将更改标题,并且搜索例程结束。
关闭浏览器窗口后,胎面将关闭。
此线程可以移至任何常规功能,以在无法更改标题的任何类型的窗口上更改标题:
Imports System.Threading
Module modWindow
Public Declare Auto Function FindWindow Lib "user32" _
(ByVal ClassName As String, ByVal WindowTitle As String) As IntPtr
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" _
(ByVal hwnd As IntPtr, ByVal lpString As String) As Long
Public thrWindow AsTread
Sub ChangeWindowTitle(sDefault as String, sCustom as String)
thrWindow = Nothing
thrWindow = new Thread(
Sub()
Dim bNoWind As Boolean = True
Dim iPtr As IntPtr
While bNoWind
iPtr = FindWindow(Nothing, sDefault)
If iPtr <> IntPtr.Zero Then
bNoWind = False
SetWindowText(iPtr, sCustom)
End If
End While
End Sub
)
thrWindow.Start()
End Sub
End Module
在子显示对话框中:
...
ChangeWindowTitle("Browse For Folder", "My Folder Browser Title")
mainForm.folderDialog.ShowDialog()
...