Isaac Zammit
Isaac Zammit

Reputation: 11

Changing the background image of a form when a progress bar expires

I am trying to make a program that once a "fake" progress bar expires, the background image of the form changes to another one. This is my first time using forms as a GUI, so I would really appreciate the help. If possible, please explain how the code works. I'm using Visual Studio 2017. Here's how the code looks like.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Form_Application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.progressBar1.Increment(1);
        }
    }
}

Upvotes: 0

Views: 253

Answers (1)

Kaj
Kaj

Reputation: 814

in this event you have to check if the progressbar value is 100 it'll be like :

private void timer1_Tick(object sender, EventArgs e)
        {
             if(progressBar1.Value<100) // set progressBar max value to 100
              {
                     // if the value smaller than 100, will increment.
                    this.progressBar1.Increment(1);
              }

          else{
                 timer1.Stop(); // Important to stop the timer
                  // here you change the background image of the form.
                  this.BackgroundImage = // choose ur image location.
              }
        }

Upvotes: 1

Related Questions