vb選擇文件夾路徑
㈠ VB的什麼控制項是可以選擇文件夾路徑
工程--部件--Microsoft Common Dailog
選擇路徑的事件
保存: showsave
打開: showopen
㈡ VB.net怎麼彈出文件夾路徑選擇框
選擇文件夾在工具箱-對話框里選擇FolderBrowserDialog添加到設計器中
然後代碼寫在按鈕事件里
FolderBrowserDialog1.ShowDialog()
textbox1.text=FolderBrowserDialog1.SelectedPath
選擇文件在工具箱-對話框里選擇OpenFileDialog
把OpenFileDialog1.ShowDialog()
TextBox1.Text=OpenFileDialog1.FileName
寫到按鈕事件下
如圖
點擊按鈕會彈出通用對話框選擇好路徑後確定,編輯框里就會顯示選擇的路徑
㈢ 請教vb6中如何選擇文件夾路徑
'在主窗體中,加入以下代碼
OptionExplicit
PrivateSubForm_Load()
Me.Caption=C_SelectPath(Me.hwnd,App.Path)'選擇文件夾路徑
EndSub
'========================================================================
'在模塊中加入下面的代碼
OptionExplicit
PrivatemSetPathAsString
PrivateTypeBrowseInfo
hWndOwnerAsLong
pIDLRootAsLong
pszDisplayNameAsLong
lpszTitleAsString
ulFlagsAsLong
lpfnCallbackAsLong
lParamAsLong
iImageAsLong
EndType
PrivateConstMAX_PATH=512&
PrivateConstBFFM_INITIALIZED=1&
PrivateConstBFFM_SELCHANGED=2&
PrivateConstWM_USER=&H400
PrivateConstBFFM_SETSTATUSTEXT=(WM_USER+100)
PrivateConstBFFM_SETSELECTION=(WM_USER+102)
PrivateConstWM_SETTEXT=&HC
PrivateConstBIF_RETURNONLYFSDIRS=1
"ole32.dll"(ByValhMemAsLong)
"shell32"(lpBIAsBrowseInfo)AsLong
"shell32.dll"Alias"SHGetPathFromIDListA"(ByValpidlAsLong,ByValpszPathAsString)AsLong
"user32.dll"Alias"SendMessageA"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,lParamAsAny)AsLong
"user32"Alias"SendMessageW"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLong
"user32"Alias"FindWindowExA"(ByValhWnd1AsLong,ByValhWnd2AsLong,ByVallpsz1AsString,ByVallpsz2AsString)AsLong
(AddAsLong)AsLong
GetAddressofFunction=Add
EndFunction
(ByValhwndAsLong,ByValuMsgAsLong,ByVallParamAsLong,ByVallpDataAsLong)AsLong
DimlpIDListAsLong
DimlRetAsLong
DimsBufferAsString
DimFhwndAsLong
DimszPath()AsByte
OnErrorGoToerrhandler
SelectCaseuMsg
CaseBFFM_INITIALIZED
CallSendMessage(hwnd,BFFM_SETSELECTION,True,ByValmSetPath)'傳遞默認路徑
Fhwnd=FindWindowEx(hwnd,0,"Edit",vbNullString)
CallSendMessage(Fhwnd,WM_SETTEXT,0,ByValmSetPath)
CaseBFFM_SELCHANGED''路徑變化
sBuffer=Space(MAX_PATH)
lRet=SHGetPathFromIDList(lParam,ByValsBuffer)
CoTaskMemFreelpIDList
IflRet=1Then
CallSendMessage(hwnd,BFFM_SETSTATUSTEXT,0,sBuffer)'改變對話框的狀態信息
Fhwnd=FindWindowEx(hwnd,0,"Edit",vbNullString)
szPath=sBuffer
CallSendMessageLong(Fhwnd,WM_SETTEXT,0,VarPtr(szPath(0)))
EndIf
EndSelect
errhandler:
BrowseCallbackProc=0
EndFunction
'使用方法:
'Me.Caption=C_SelectPath(Me.hwnd,App.Path)'選擇文件夾路徑
PublicFunctionC_SelectPath(m_hwmd&,strPathAsString)AsString
DimlpIDListAsLong
DimudtBIAsBrowseInfo
WithudtBI'初試化udtBI結構
mSetPath=strPath'設置默認路徑
.hWndOwner=m_hwmd
.ulFlags=BIF_RETURNONLYFSDIRSOr&H10Or&H40'&H10=路徑框&H40=新建文件夾
.lpszTitle="請選擇文件夾:"
.lpfnCallback=GetAddressofFunction(AddressOfBrowseCallbackProc)'getaddressoffunction.
EndWith
lpIDList=SHBrowseForFolder(udtBI)'彈出文件夾查看窗口
IflpIDListThen
DimsPathAsString,retAsLong
sPath=String$(MAX_PATH,0)
ret=SHGetPathFromIDList(ByVallpIDList,ByValsPath)
CallCoTaskMemFree(lpIDList)
IfretThen
C_SelectPath=Replace(sPath,Chr(0),"")
EndIf
EndIf
EndFunction
㈣ vb 選擇文件 獲取文件路徑
首先在窗體中放置
Microsoft
Common
Dialog
Control,名稱指定為
cdlg1。
然後放一個按鈕,代碼如下:
Private
Sub
Command1_Click()
Dim
fname
As
String
Dim
content
As
String
cdlg1.ShowOpen
fname
=
cdlg1.FileName
MsgBox
fname
Open
fname
For
Input
As
#1
Input
#1,
content
MsgBox
content
Close
#1
End
Sub
㈤ VB獲取文件夾路徑
只說
原理
。先建立FSO
對象遍歷磁碟
查找名稱為"「的文件夾
,返回全路徑
㈥ VB選擇文件路徑代碼
點擊「打開」按鈕後,調用本函數,在出現的選擇文件對話框中選擇好文件,點擊確定後會返迴文件路徑。
01 Function FPath$(nhwnd&, Title$)
02 Dim bi As BROWSEINFO
03 Dim idl As ITEMIDLIST
04 Dim rtn&, pidl&, path$, pos%
05 bi.hOwner = nhwnd&
06 bi.pidlRoot = idl.mkid.cb
07 bi.lpszTitle = Title$
08 bi.ulFlags = &H1
09 pidl& = SHBrowseForFolder(bi)
10 path$ = Space$(512)
11 rtn& = SHGetPathFromIDList(ByVal pidl&, ByVal path$)
12 pos% = InStr(path$, Chr$(0))
13 FPath$ = Left(path$, pos - 1)
14 End Function
㈦ vb中獲取選擇文件夾的路徑
Private Declare Function icePub_getSelectPath Lib "icePubDll.dll" (ByVal strPath As String,ByVal maxLen As Integer) As Integer
Dim str1 As String
Dim a2 As Integer
str1 = Space(1024*10+1)
a2 = = icePub_getSelectPath(str1,1024*10)
MsgBox str1
㈧ vb怎麼實現彈出對話框選擇文件路徑
VB6.0使用CommonDialog 控制項彈出對話框選擇文件路徑。
通過使用 CommonDialog 控制項的 ShowOpen 和 ShowSave
方法可顯示「打開」和「另存為」對話框。
兩個對話框均可用以指定驅動器,目錄,文件擴展名和文件名。除對話的標題不同外,另存為對話外觀上與打開對話相似。
下例顯示「打開」對話框然後在信息框中顯示所選的文件名:
PrivateSubCommand1_Click()
'設置「CancelError」為True
CommonDialog1.CancelError=True
OnErrorGoToErrHandler
'設置標志
CommonDialog1.Flags=cdlOFNHideReadOnly
'設置過濾器
CommonDialog1.Filter="AllFiles(*.*)|*.*|TextFiles"&_
"(*.txt)|*.txt|BatchFiles(*.bat)|*.bat"
'指定預設的過濾器
CommonDialog1.FilterIndex=2
'顯示「打開」對話框
CommonDialog1.ShowOpen
'顯示選定文件的名字
MsgBoxCommonDialog1.FileName'顯示路徑
ExitSub
ErrHandler:
'用戶按了「取消」按鈕
ExitSub
EndSub