您的位置首页百科知识

VB中如何添加图片

VB中如何添加图片

新建工程,点菜单:工程\部件\——选:Microsoft Common Dialog Control 6.0在窗体中加入:Command1、CommonDialog1,将下列代码Copy到代码窗口中:Private Sub Command1_Click() '文件蚂判液打闷物开On Error Resume Next '设置错误处理Dim openFilename As StringWith 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 '允许长文件名.ShowOpenIf Err.Number = 32755 Then Exit Sub '若按取冲做消按钮,则退出过程openFilename = .FileName '获得要打开的文件名Form1.Picture = LoadPicture(openFilename)End WithEnd SubPrivate Sub Form_Load()Command1.Caption = "选择图片"End Sub