vb编写程序:VB编写带图片预览的对话框程序来源: 发布时间:星期四, 2008年9月25日 浏览:128次 评论:0
用户在图片框中选择图片时,希望预先对图片的轮廓及大小有初步了解,但是VB的通用对话框没有预览的功能,为此需要定制一个自定义对话框。我们可以通过image控件加入窗体中来实现其功能。
程序示例: 程序功能说明: 在窗体的file1中选择一个图片文件,点选“预览”复选框,image控件就显示相应的图片,label1就显示该图片的大小。 新建一个工程,加入以下控件: 控件名称属性 formform1borderstyle=3 (vbsizedouble) caption=“图片预览对话框\" drivelistboxdrive1 dirlistboxdir1 filelistboxfile1pattern=“*.bmp; *.jpg;*.gif\" imageimage1stretch=true checkboxchkvalue=“预览\" commandbuttoncmd1caption=“确定\" cmd2caption=“退出\" labellab1caption=“\" 源代码: ’declare Publicfilename$ dimsfilename$ Privatesubdrive1_change() dir1.path=drive1.drive Endsub Privatesubdir1_change() file1.path=dir1.path Endsub Privatesubcmd1_click() filename=sfilename Endsub Privatesubcmd2_click() End Endsub Privatesubfile1_click() dimssizeaslong iffille1.listcount>0then ifright(file1.path,1)<>“\\\"then sfilename=file1.path&“\\\"&file1.filename else sfilename=file1.path&file1.filename Endif ifchk.checkedthen image1.picture=loadpicture(“\") image1.picture=loadpicture(sfilename) ssize=filelen(sfilename) ssize=ssize/1000 lab1.caption=str(ssize)&“k\" else lab1.caption=“\" image1.picture=loadpicture(“\") endif endif Endsub 0
相关文章
读者评论
发表评论 |