vb随机显示图片

2019-04-15 13:46发布

根目录下建一个文件夹PIC,在PIC下存放5张图片, 名称分虽是1,2,3,4,5 然后添加一个timer1控件,一个image1控件, 它的interval设5000(即5秒)

写如下代码

Private Sub Form_Load() Dim i As Integer Image1.Picture = LoadPicture(App.Path & "pic1.bmp") End Sub



Private Sub Timer1_Timer() i = Int(Rnd * 5 + 1) Image1.Picture = LoadPicture(App.Path & "pic" & i & ".bmp") End Sub