如何让图片框中的图片每10秒更换一次

时间:2013-06-17 20:37:04

标签: vb.net visual-studio-2010

我正在制作闭路电视摄像机,我希望图片框中的图片每十秒钟更换一次,有人可以帮助我。我尝试过使用

pic1.Image = Image.FromFile("C:\Documents and Settings\IT\My Documents\Downloads\whitehouse 
System.Threading.Thread.Sleep(10000)
pic1.Image = Image.FromFile("C:\Documents and Settings\IT\My Documents\Downloads\penatagon")

1 个答案:

答案 0 :(得分:2)

有几件事: 如果这些图像不是太大而且很丰富,你应该考虑预先加载它们:

Dim images As New List(Of Image)()
images.add(Image.FromFile(Somefilepath))

现在创建一个每10秒钟打一次的计时器:

  Dim pictureChangeTimer As New Timer()
    'Creates a timer
    AddHandler pictureChangeTimer.Tick, AddressOf pictureChangeTimer_tick
    'creates an event handler, simply type in pictureChangeTimer.Tick += and hit tab twice. this will automatically create the method for you
    ' Sets the timer interval to 10 seconds.
    myTimer.Interval = 10000
    myTimer.Start()

现在,在单独的功能中,您可以在每次事件发生时更改图片

  Private Sub pictureChangeTimer_tick(sender As Object, e As EventArgs)
    'if using a list
    pic1.Image = images(Index)
    'using your original example
    pic1.Image = Image.FromFile("C:\Documents and Settings\IT\My Documents\Downloads\whitehouse.jpg")
End Sub