Visual Basic中实现带预览的对话框

资讯 驱动中国 若水 1,108 次阅读 0 条评论
分享 Q
用户在图片框中选择图片时,希望预先对图片的轮廓及大小有初步了解,但是VB的通用对话框没有预览的功能,为此需要定制一个自定义对话框。我们可以通过image控件加入窗体中来实现其功能。

程序示例:用户在图片框中选择图片时,希望预先对图片的轮廓及大小有初步了解,但是VB的通用对话框没有预览的功能,为此需要定制一个自定义对话框。我们可以通过image控件加入窗体中来实现其功能。

程序示例:

程序功能说明:

在窗体的file1中选择一个图片文件,点选“预览”复选框,image控件就显示相应的图片,label1就显示该图片的大小。

新建一个工程,加入以下控件:

控件 名称 属性

form form1 borderstyle=3

(vbsizedouble)

caption=“图片预览对话框"

drivelistbox drive1

dirlistbox dir1

filelistbox file1 pattern=“*.bmp;

*.jpg;*.gif"

image image1 stretch=true

checkbox chk value=“预览"

commandbutton cmd1 caption=“确定"

cmd2 caption=“退出"

label lab1 caption=“"

源代码:

以下是引用片段:
'declare
Public filename$
dim sfilename$
Private sub drive1_change()
dir1.path=drive1.drive
End sub
Private sub dir1_change()
file1.path=dir1.path
End sub
Private sub cmd1_click()
filename=sfilename
End sub
Private sub cmd2_click()
End
End sub
Private sub file1_click()
dim ssize as long
if fille1.listcount>0 then
if right(file1.path,1)<>“\" then
sfilename=file1.path&“\"&file1.filename
else
sfilename=file1.path&file1.filename
End if
if chk.checked then
image1.picture=loadpicture(“")
image1.picture=loadpicture(sfilename)
ssize=filelen(sfilename)
ssize=ssize/1000
lab1.caption=str(ssize)&“k"
else
lab1.caption=“"
image1.picture=loadpicture(“")
end if
end if
End sub 


程序功能说明:

在窗体的file1中选择一个图片文件,点选“预览”复选框,image控件就显示相应的图片,label1就显示该图片的大小。

新建一个工程,加入以下控件:

控件 名称 属性

form form1 borderstyle=3

(vbsizedouble)

caption=“图片预览对话框"

drivelistbox drive1

dirlistbox dir1

filelistbox file1 pattern=“*.bmp;

*.jpg;*.gif"

image image1 stretch=true

checkbox chk value=“预览"

commandbutton cmd1 caption=“确定"

cmd2 caption=“退出"

label lab1 caption=“"

源代码:

以下是引用片段:
'declare
Public filename$
dim sfilename$
Private sub drive1_change()
dir1.path=drive1.drive
End sub
Private sub dir1_change()
file1.path=dir1.path
End sub
Private sub cmd1_click()
filename=sfilename
End sub
Private sub cmd2_click()
End
End sub
Private sub file1_click()
dim ssize as long
if fille1.listcount>0 then
if right(file1.path,1)<>“\" then
sfilename=file1.path&“\"&file1.filename
else
sfilename=file1.path&file1.filename
End if
if chk.checked then
image1.picture=loadpicture(“")
image1.picture=loadpicture(sfilename)
ssize=filelen(sfilename)
ssize=ssize/1000
lab1.caption=str(ssize)&“k"
else
lab1.caption=“"
image1.picture=loadpicture(“")
end if
end if
End sub
版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友