在VB中怎样用代码打开pictureBox的加载图片的对话框。 10

 我来答
沙慧月03
2011-11-13 · TA获得超过2157个赞
知道大有可为答主
回答量:2717
采纳率:100%
帮助的人:3606万
展开全部
简单实例:按钮一个,commondialog控件一个
Private Sub cmdgxbj_Click()
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName
If Dir(FileName) = "" Then
'填写的路径不存在就退出
Exit Sub
End If
Picture1.Picture = LoadPicture(FileName)
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
HeXian000
2011-11-13 · TA获得超过339个赞
知道小有建树答主
回答量:502
采纳率:0%
帮助的人:366万
展开全部
对话框要自己另编,建议使用CommonDialog控件
CommonDialog用法:
http://www.360doc.com/content/09/0609/08/19147_3823176.shtml
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
行深慎独k
2011-11-14 · TA获得超过726个赞
知道小有建树答主
回答量:393
采纳率:87%
帮助的人:147万
展开全部
在模块中
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
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zy4517zy
2011-11-13 · TA获得超过302个赞
知道答主
回答量:357
采纳率:0%
帮助的人:206万
展开全部
这个应该是很简单的, 书上讲控件那里去找一下吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式