下面给你详细的代码,好好研究。你将生成的应用程序和图片文件夹Photo放在一个平行的文件夹里(如图),本代码功能:随便你放“任意数量”的照片(图片类型包括:*.jpg;*.bmp;*.gif;*.ico四类)到Photo文件夹内都可以显示。
控件布局如图所示即可,代码如下:简庆
Dim AppPath As String, ShunXu As Boolean, ShuLiang As Long, a As Long
Private Sub Check1_Click()
If Check1.Value = 1 Then
ShunXu = False
Check2.Value = 0
Else
ShunXu = True
Check2.Value = 1
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
ShunXu = True
Check1.Value = 0
扮颂 Else
ShunXu = False
Check1.Value = 1
End If
End Sub
Private Sub Command1_Click()
ShuLiang = File1.ListCount
If ShuLiang > 0 Then Timer1.Enabled = True Else MsgBox "没有图片哦"
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
If Right(App.Path, 1) = "\" Then AppPath = App.Path Else AppPath 厅咐郑= App.Path & "\"
Check1.Value = 1
Check2.Value = 0
ShunXu = False '顺序播放
Timer1.Interval = 500 '半秒钟循环一次
Timer1.Enabled = False
Command1.Caption = "预 览"
Command2.Caption = "停 止"
Check1.Caption = "顺序"
Check2.Caption = "随机"
Image1.Stretch = True
Image1.BorderStyle = 1
File1.Path = AppPath & "Photo"
File1.Pattern = "*.jpg;*.bmp;*.gif;*.ico"
ShuLiang = File1.ListCount
a = 0
End Sub
Private Sub Timer1_Timer()
If ShunXu Then '随机
Randomize: a = Int(ShuLiang * Rnd)
Image1.Picture = LoadPicture(AppPath & "Photo\" & File1.List(a))
Else '顺序
Image1.Picture = LoadPicture(AppPath & "Photo\" & File1.List(a))
a = a + 1
If a > ShuLiang - 1 Then a = 0
End If
File1.Selected(a) = True
End Sub
更换方法
randomize
rnd()
两个函数
取1-6的整数值,即可
可以详细详细点么。。。。
yangyingjun999 的代码挺好的 没测试 但看着效果不错
而且增加了很多附加功能
我做了个简单的
Private Sub Command1_Click()
Static a As Boolean '定义静态变量,用来判定点击按钮的状态
If a = True Then
Me.Command1.Caption = "点击开始"
a = True
Me.Timer1.Enabled = False
Call RndPic
Else
Me.Command1.Caption = "停止"
a = False
Me.Timer1.Enabled = True
End If
End Sub
Private Sub Form_Load() '初始化主要参数
Me.Timer1.Enabled = False
Me.Timer1.Interval = 80
Me.Command1.Caption = "点击开始"
End Sub
Private Sub Timer1_Timer()
Call RndPic
End Sub
Sub RndPic()
Static n As Integer
Randomize '给个随机种子
n = (Rnd() * 1000 Mod 6) + 1 '随机数,由于rnd()的范围是[0,1),即>=0并<1的,再*1000因此产生的是[0,1000)的数值,再mod取6的余数,这时范围为0-5,再加1,就是1-6了。
Me.Picture = LoadPicture("C:\" & CStr(n) & ".jpg") '使用loadpicture方法载入以数组方式命名的图片
End Sub
准备工作,
1在窗体上加两个控件,一个是timer1,一个是command1
2再在c盘的根目录放6张jpg图片,分别为1.jpg,2.jpg,3.jpg......6.jpg
然后运行以上代码
广告 您可能关注的内容 |