有控件的 添加部件 Microsoft common Dialog control 6.0 (sp6)
CommonDialog1.DialogTitle = "打开要修改的描述文件" CommonDialog1.Filter = "(*.cfg)|*.cfg|(*.txt)|*.txt" CommonDialog1.ShowOpen’显示打开文件地址Label1.Caption = CommonDialog1.FileName If CommonDialog1.FileName = "" Then Exit Sub End If
Option Explicit '强制宣告定义变量 Dim DeskPath$ '定义变量 Private Sub Form_Load() '将窗体居中显示 (屏幕宽度减去窗体的宽度)除以2 , (屏幕高度减去窗体的高度)除以2 Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2 End SubPrivate Sub Command1_Click() DeskPath = GetDeskPath Me.Picture = LoadPicture(DeskPath & "\桌面.jpg") End SubPublic Function GetDeskPath() As String Dim WshShell Set WshShell = CreateObject("Wscript.shell") GetDeskPath = WshShell.SpecialFolders("Desktop") End Function
通用对话框控件:Microsoft common Dialog control 6.0 (sp6)
你那是文件夹选择对话框。 Microsoft Visual Studio .NET 中有相应的标准控件。不知道是否有这个相应的API。 要选择文件夹,有个替代方案。 你参考一下这个代码: Private Sub Command1_Click() Dim SelFolder$ Dim spShell As Object Dim spFolder As Object Dim spFolderItem As Object On Error GoTo Err_Proc Set spShell = CreateObject("Shell.Application") Set spFolder = spShell.BrowseForFolder(0, "选择目录!", 1, "") Set spFolderItem = spFolder.Self SelFolder = spFolderItem.Path Debug.Print SelFolder Exit Sub Err_Proc: If Err > 0 Then Exit Sub End Sub
file:///C:/Documents%20and%20Settings/188964/Desktop/桌面.jpg
添加部件 Microsoft common Dialog control 6.0 (sp6)
CommonDialog1.Filter = "(*.cfg)|*.cfg|(*.txt)|*.txt"
CommonDialog1.ShowOpen’显示打开文件地址Label1.Caption = CommonDialog1.FileName
If CommonDialog1.FileName = "" Then
Exit Sub
End If
Dim DeskPath$ '定义变量
Private Sub Form_Load()
'将窗体居中显示 (屏幕宽度减去窗体的宽度)除以2 , (屏幕高度减去窗体的高度)除以2
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
End SubPrivate Sub Command1_Click()
DeskPath = GetDeskPath
Me.Picture = LoadPicture(DeskPath & "\桌面.jpg")
End SubPublic Function GetDeskPath() As String
Dim WshShell
Set WshShell = CreateObject("Wscript.shell")
GetDeskPath = WshShell.SpecialFolders("Desktop")
End Function
Microsoft Visual Studio .NET 中有相应的标准控件。不知道是否有这个相应的API。
要选择文件夹,有个替代方案。
你参考一下这个代码:
Private Sub Command1_Click()
Dim SelFolder$
Dim spShell As Object
Dim spFolder As Object
Dim spFolderItem As Object
On Error GoTo Err_Proc
Set spShell = CreateObject("Shell.Application")
Set spFolder = spShell.BrowseForFolder(0, "选择目录!", 1, "")
Set spFolderItem = spFolder.Self
SelFolder = spFolderItem.Path
Debug.Print SelFolder
Exit Sub
Err_Proc:
If Err > 0 Then Exit Sub
End Sub