在VB中怎样用代码打开pictureBox的加载图片的对话框。 10
4个回答
展开全部
简单实例:按钮一个,commondialog控件一个
Private Sub cmdgxbj_Click()
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName
If Dir(FileName) = "" Then
'填写的路径不存在就退出
Exit Sub
End If
Picture1.Picture = LoadPicture(FileName)
End Sub
Private Sub cmdgxbj_Click()
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName
If Dir(FileName) = "" Then
'填写的路径不存在就退出
Exit Sub
End If
Picture1.Picture = LoadPicture(FileName)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
对话框要自己另编,建议使用CommonDialog控件
CommonDialog用法:
http://www.360doc.com/content/09/0609/08/19147_3823176.shtml
CommonDialog用法:
http://www.360doc.com/content/09/0609/08/19147_3823176.shtml
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在模块中
Option Explicit
'对话框
Public Declare Function GetOpenFileName _
Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Public Declare Function GetSaveFileName _
Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Public Declare Function SHBrowseForFolder Lib "shell32.dll" (lpBrowseInfo As BROWSEINFO) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal pidl As Long, pszPath As String) As Long
Public Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As ChooseColor) As Long
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlage As Long
lpfn As Long
lparam As Long
iImage As Long
End Type
Private Type ChooseColor
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Const OFN_HIDEREADONLY = &H4 '隐藏只读打开
Public Const OFN_READONLY = &H1 '只读打开为选中
Public Const OFN_OVERWRITEPROMPT = &H2 '覆盖时提示
Public Const OFN_ALLOWMULTISELECT = &H200 '多个选中
Public Const OFN_EXPLORER = &H80000 '资源管理器
Public Function ShowOpen(MehWnd As Long, _
FileOpen As String, _
Optional Title As String = "打开: ", _
Optional Filter As String = vbNullChar + vbNullChar, _
Optional FilterIndex As Long = 0, _
Optional StartDir As String = vbNullChar, _
Optional flags As Long = OFN_HIDEREADONLY) As Long
Dim OpenFN As OPENFILENAME
Dim Rc As Long
With OpenFN
.hwndOwner = MehWnd
.hInstance = App.hInstance
.lpstrTitle = Title
.lpstrFilter = Filter
.nFilterIndex = FilterIndex
.lpstrInitialDir = StartDir
.lpstrFile = String$(256, 0)
.nMaxFile = 255
.lpstrFileTitle = .lpstrFile
.nMaxFileTitle = 255
.flags = flags
.lStructSize = Len(OpenFN)
End With
Rc = GetOpenFileName(OpenFN)
If Rc Then
FileOpen = Left$(OpenFN.lpstrFile, OpenFN.nMaxFile)
ShowOpen = True
Else
ShowOpen = False
End If
End Function
然后在窗体中这样调用
dim sBuffer as string
ShowOpen me.hWnd, sBuffer
Option Explicit
'对话框
Public Declare Function GetOpenFileName _
Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Public Declare Function GetSaveFileName _
Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Public Declare Function SHBrowseForFolder Lib "shell32.dll" (lpBrowseInfo As BROWSEINFO) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal pidl As Long, pszPath As String) As Long
Public Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As ChooseColor) As Long
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlage As Long
lpfn As Long
lparam As Long
iImage As Long
End Type
Private Type ChooseColor
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Const OFN_HIDEREADONLY = &H4 '隐藏只读打开
Public Const OFN_READONLY = &H1 '只读打开为选中
Public Const OFN_OVERWRITEPROMPT = &H2 '覆盖时提示
Public Const OFN_ALLOWMULTISELECT = &H200 '多个选中
Public Const OFN_EXPLORER = &H80000 '资源管理器
Public Function ShowOpen(MehWnd As Long, _
FileOpen As String, _
Optional Title As String = "打开: ", _
Optional Filter As String = vbNullChar + vbNullChar, _
Optional FilterIndex As Long = 0, _
Optional StartDir As String = vbNullChar, _
Optional flags As Long = OFN_HIDEREADONLY) As Long
Dim OpenFN As OPENFILENAME
Dim Rc As Long
With OpenFN
.hwndOwner = MehWnd
.hInstance = App.hInstance
.lpstrTitle = Title
.lpstrFilter = Filter
.nFilterIndex = FilterIndex
.lpstrInitialDir = StartDir
.lpstrFile = String$(256, 0)
.nMaxFile = 255
.lpstrFileTitle = .lpstrFile
.nMaxFileTitle = 255
.flags = flags
.lStructSize = Len(OpenFN)
End With
Rc = GetOpenFileName(OpenFN)
If Rc Then
FileOpen = Left$(OpenFN.lpstrFile, OpenFN.nMaxFile)
ShowOpen = True
Else
ShowOpen = False
End If
End Function
然后在窗体中这样调用
dim sBuffer as string
ShowOpen me.hWnd, sBuffer
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个应该是很简单的, 书上讲控件那里去找一下吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询