首页 > 解决方案 > 进度条过期时更改表单的背景图像

问题描述

我正在尝试制作一个程序,一旦“假”进度条过期,表单的背景图像就会更改为另一个。这是我第一次将表单用作 GUI,因此我非常感谢您的帮助。如果可能,请解释代码是如何工作的。我正在使用 Visual Studio 2017。代码如下所示。

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);
        }
    }
}

标签: c#

解决方案


在这种情况下,您必须检查进度条值是否为 100,它会像:

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.
              }
        }

推荐阅读