现在要做个 程序,可以 快速循环显示一个文件夹中的图片。
要求点击图片就停止循环。
(实际就是一个根据图片抽奖程序),现在循环的时候 form经常白屏,不显示图片。
另外循环显示的时候无法响应其他事件。vb小菜鸟求达人帮助,OK立即结贴。Dim index, allindex As Integer
 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Sleep 1000   '延时1000毫秒If index > 0 Then
index = index - 1
Else
index = allindex - 1
End IfCall InitShowPicEnd SubPrivate Sub Command2_Click()
If index < allindex - 1 Then
index = index + 1
Else
index = 0
End If
Call InitShowPic
End SubPrivate Sub Command3_Click()
Dim i As IntegerFor i = 1 To 20
index = index + 1
Call InitShowPic
Form1.Refresh
Sleep 200
NextEnd SubPrivate Sub Command4_Click()End SubPrivate Sub Dir1_Change()
File1.Path = Dir1.Path
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End SubPrivate Sub File1_Click()
Image1.Picture = LoadPicture(Dir1.Path + "\" + File1.List(File1.ListIndex))
End SubPrivate Sub Form_Load()
Drive1.Drive = "c:"
Dir1.Path = "c:\mop\"
index = 0
allindex = File1.ListCount
End SubPrivate Sub InitShowPic()    Image1.Picture = LoadPicture(Dir1.Path + "\" + File1.List(index))End SubPrivate Sub File1_PathChange()
'Call InitShowPic
End Sub

解决方案 »

  1.   

    Private Sub InitShowPic()     Image1.Picture = LoadPicture(Dir1.Path + "\" + File1.List(index))
        DoEventsEnd Sub 
      

  2.   

    sleep会使主程序停止响应,改用delayprivate sub delay( byval t as double )
        dim s as double
        s = timer
        do
            doevents
        loop while timer - s < t
    end sub
      

  3.   

    方法有问题。在循环中LOADPICTURE肯定是反应不过来的。
    改成:一次性加载所有图片,然后BITBLT贴图,速度就没问题了。
      

  4.   

    关于白屏问题:
    速度快了,是要白一些,不过要是闪烁,可以换PICTUREBOX控件,虽然不支持透明,但刷新比较流畅。
    另外
    吧要显示的图片全部读到imagelist控件中,然后在一次输出到图片控件中,才是正宗做法。imagelist中可以设置透明,而且效果流畅。