C#-在4秒钟内显示加载量为1-100% [英] C# - Display loading 1-100% within 4 seconds

查看:81
本文介绍了C#-在4秒钟内显示加载量为1-100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在启动屏幕上显示了一个标签,显示了4秒钟.我正在尝试使标签以百分比形式显示加载过程.显然,这只是向用户显示该程序实际上正在启动,而不是实际上在加载"任何东西.有没有办法让我的标签在4秒钟内显示百分比(从1%到100%)?在执行此操作时有些失落.

I have a label on a splash screen that is displayed for 4 seconds. I am trying to make the label display the loading process as a percentage. Obviously, this is just to show the user that the program is actually starting up and not actually "loading" anything. Is there a way that I can have the label display the percentage (going from 1% to 100%) within 4 seconds? A bit lost on how to do this.

推荐答案

在窗体上放置一个Timer控件,并将其Interval属性设置为40,并将其Enabled属性设置为true.创建这样的表单级变量:

Put a Timer control on the form, and set its Interval property to 40 and its Enabled property to true. Create a form-level variable like this:

private int _Progress = 0;

在计时器的滴答"事件中,输入以下代码:

In the Timer's Tick event, put this code:

if (_Progress < 100)
{
    _Progress++;
    label1.Text = _Progress.ToString() + "%";
}
else
{
    timer1.Enabled = false;
}

计时器的精确度并没有达到毫秒级,因此并不需要4秒钟,但是可以完成工作.

Timers aren't really accurate to the millisecond, so this won't take exactly 4 seconds, but it will do the job.

这篇关于C#-在4秒钟内显示加载量为1-100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆