如何让图片框中的图片每 10 秒更改一次 [英] how to have a picture in a picture-box change every 10 seconds

查看:23
本文介绍了如何让图片框中的图片每 10 秒更改一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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

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

现在创建一个每 10 秒滴答一次的计时器:

Now create a Timer that will tick every 10 seconds:

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.
pictureChangeTimer.Interval = 10000
pictureChangeTimer.Start()

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

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

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

这篇关于如何让图片框中的图片每 10 秒更改一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆