---
title: "How to periodically change background image"  
description: "How to periodically change background image"  
author: "Anonymous User"  
published: 2013-10-05  
updated: 2013-10-05  
canonical: https://www.mindstick.com/forum/1596/how-to-periodically-change-background-image  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 1 minute  

---

# How to periodically change background image

I have 2 forms, frmMain and frmPictures. In frmMain I have a [timer](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) whose interval is 5000 (5 seconds). frmPictures has 16 pictureboxes with [images](https://www.mindstick.com/interview/1067/what-is-the-php-predefined-variable-that-tells-the-what-type-of-images-that-php-support) [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) loaded in them. In each timer tick I need to change the frmMain [background image](https://www.mindstick.com/forum/539/css-background-image-properties-not-work-in-outlook).. on [startup](https://www.mindstick.com/articles/167716/6-reasons-why-you-should-lawyer-up-your-startup) the background image is the same as picturebox1.\
\
On each timer tick, the [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) should randomly [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) a PictureBox in frmPictures and change the background image of frmMain to the image of the selected PictureBox.\
\
How do I do this in [VB.NET](https://www.mindstick.com/forum/426/sqlsever-2000-in-network-with-vb-dot-net-2008)?

## Replies

### Reply by Anonymous User

Firstly, you should gather all PictureBoxes in an array or similar structure. That can happen e.g. in the Form_Load event:

```
Dim pictures(15) As PictureBox
pictures(0) = frmPictures.PictureBox1
```

\

Btw, why do you have PictureBoxes for each picture? It would be sufficient to load

the images at application startup:

```
Dim pictures(15) As Image
pictures(0) = Image.FromFile("...")
```

\

Then in the timer event, create a random number and pick an [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character):

```
Dim rnd = CInt(16 * Rnd())
BackgroundImage = pictures(rnd).Image
BackgroundImage = pictures(rnd)    
```

\

\


---

Original Source: https://www.mindstick.com/forum/1596/how-to-periodically-change-background-image

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
