我通过commondialog打开图片,要求图像在Picturebox中显示,但是为什么显示不出来
代码:PrivateSubCommand1_Click()OnErrorGoToErr_HandleDimFileNames()AsStringCommonDialog1...
代码:
Private Sub Command1_Click()
On Error GoTo Err_Handle
Dim FileNames() As String
CommonDialog1.FileName = ""
CommonDialog1.Filter = "图像文件|*.jpg;*.gif;*.png;*.PNG;*.bmp"
CommonDialog1.Flags = cdlOFNAllowMultiselect
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialon1.FileName)
Picture2.Picture = LoadPicture(CommonDialon1.FileName)
If Err.Number = 481 Then
MsgBox "请选择图片文件"
End If
Exit Sub
Err_Handle:
Exit Sub
End Sub 展开
Private Sub Command1_Click()
On Error GoTo Err_Handle
Dim FileNames() As String
CommonDialog1.FileName = ""
CommonDialog1.Filter = "图像文件|*.jpg;*.gif;*.png;*.PNG;*.bmp"
CommonDialog1.Flags = cdlOFNAllowMultiselect
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialon1.FileName)
Picture2.Picture = LoadPicture(CommonDialon1.FileName)
If Err.Number = 481 Then
MsgBox "请选择图片文件"
End If
Exit Sub
Err_Handle:
Exit Sub
End Sub 展开
2个回答
展开全部
Private Sub Command1_Click()
'On Error GoTo Err_Handle '
Dim FileNames() As String
CommonDialog1.FileName = ""
CommonDialog1.Filter = "图像文件|*.jpg;*.gif;*.png;*.PNG;*.bmp"
CommonDialog1.Flags = cdlOFNAllowMultiselect '这个选项可使多选,所以要对文件串进行处理。
CommonDialog1.ShowOpen
Dim a
a = Split(CommonDialog1.FileName, " ")
If UBound(a) = 0 Then Picture1.Picture = LoadPicture(a(0))
If UBound(a) > 0 Then Picture1.Picture = LoadPicture(a(0) & a(1))
If UBound(a) > 1 Then Picture2.Picture = LoadPicture(a(0) & a(2))
If Err.Number = 481 Then
MsgBox "请选择图片文件"
End If
Exit Sub
Err_Handle:
Exit Sub
End Sub
展开全部
主要是你用错了名字:
Picture1.Picture = LoadPicture(CommonDialon1.FileName)
Picture2.Picture = LoadPicture(CommonDialon1.FileName)
应该是:
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
Picture2.Picture = LoadPicture(CommonDialog1.FileName)
Picture1.Picture = LoadPicture(CommonDialon1.FileName)
Picture2.Picture = LoadPicture(CommonDialon1.FileName)
应该是:
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
Picture2.Picture = LoadPicture(CommonDialog1.FileName)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询