新建工程,点菜单:工程\部件\——选:Microsoft Common Dialog Control 6.0
在窗体中加入:Command1、CommonDialog1,
将下列代码Copy到代码窗口中:
Private Sub Command1_Click() '文件打开
On Error Resume Next '设置错误处理
Dim openFilename As String
With CommonDialog1
.CancelError = True
.InitDir = "C:\"
.Filter = "位图文件(*.BMP)|*.BMP|JPEG(*.JPG;*.JPEG;*.JPE;*.JFIF)|*.JPG;*.JPEG;*.JPE;*.JFIF|GIF(*.GIF)|*.GIF|TIF(*.TIF;*.TIFF)|*.TIF;*.TIFF|所有文件|*.*"
.FilterIndex = 2
.Flags = &H200000 '允许长文件名
.ShowOpen
If Err.Number = 32755 Then Exit Sub '若按取消按钮,则退出过程
openFilename = .FileName '获得要打开的文件名
Form1.Picture = LoadPicture(openFilename)
End With
End Sub
Private Sub Form_Load()
Command1.Caption = "选择图片"
End Sub
Visual Basic code
?
1
Form1.Picture1.Picture = LoadPicture("路径")