vb.net 如何让图片框中的图片每 10 秒更改一次

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17156391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:56:39  来源:igfitidea点击:

how to have a picture in a picture-box change every 10 seconds

vb.netvisual-studio-2010

提问by user2494890

I am making a CCTV camera sort of thing and I want the pictures in the picture-boxes to change every ten seconds can someone please help me. i have tried using

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

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")

回答by Mataniko

A couple of things: If these images aren't too big and plentiful you should consider preloading them all before hand:

有几件事:如果这些图像不是太大和太多,您应该考虑事先预先加载它们:

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

Now create a Timer that will tick every 10 seconds:

现在创建一个每 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()

Now in a separate function you can change your pictures every time the event lauches

现在在一个单独的功能中,您可以在每次活动开始时更改图片

  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