c# - 进度条过期时更改表单的背景图像
问题描述
我正在尝试制作一个程序,一旦“假”进度条过期,表单的背景图像就会更改为另一个。这是我第一次将表单用作 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);
}
}
}
解决方案
在这种情况下,您必须检查进度条值是否为 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.
}
}
推荐阅读
- python - NumPy:生成包含特定元素的随机子集的最快方法
- vue.js - 如何使用 vue-tables-2 隐藏列 - Vuejs -
- javascript - JavaScript 预加载器无法正常工作
- java - 为什么我们扩展 JpaRepository 接口而不是实现它
- c# - 查看泛型类的所有特殊用途
- jquery - 显示 div 时未触发 Jquery 事件:无
- git - 主人似乎是发展的孩子
- python - 如何在 Pandas 中管理多个条件
- django - ContentType 对象的 DRF 序列化程序返回 null
- laravel - 为什么此保存功能在本地项目上有效,但在服务器和 cpanel 上无效?