Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何定期更改背景图像_Vb.net_Timer - Fatal编程技术网

Vb.net 如何定期更改背景图像

Vb.net 如何定期更改背景图像,vb.net,timer,Vb.net,Timer,我有两种形式,一种是货币,另一种是货币。在frmMain中,我有一个间隔为5000(5秒)的计时器。FRMPactures有16个已加载图像的图片盒。在每一个计时器滴答声中,我需要更改frmMain背景图像。。启动时,背景图像与picturebox1相同。在每个计时器滴答声中,程序应在FRMPactures中随机选择一个PictureBox,并将frmMain的背景图像更改为所选PictureBox的图像。如何在VB.NET中执行此操作?首先,您应该将所有图片框收集在一个数组或类似结构中。这可能

我有两种形式,一种是货币,另一种是货币。在frmMain中,我有一个间隔为5000(5秒)的计时器。FRMPactures有16个已加载图像的图片盒。在每一个计时器滴答声中,我需要更改frmMain背景图像。。启动时,背景图像与picturebox1相同。

在每个计时器滴答声中,程序应在FRMPactures中随机选择一个PictureBox,并将frmMain的背景图像更改为所选PictureBox的图像。

如何在VB.NET中执行此操作?

首先,您应该将所有
图片框
收集在一个数组或类似结构中。这可能会发生,例如在
表单加载事件中:

Dim pictures(15) As PictureBox
pictures(0) = frmPictures.PictureBox1
'...
顺便问一下,为什么每张图片都有图片盒?在应用程序启动时加载映像就足够了:

Dim pictures(15) As Image
pictures(0) = Image.FromFile("...")
'...
然后在计时器事件中,创建一个随机数并拾取图像:

'Call Randomize() on application startup
Dim rnd = CInt(16 * Rnd())
BackgroundImage = pictures(rnd).Image 'For the picture box method or
BackgroundImage = pictures(rnd)       'For the direct method