Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# winforms中进度条的使用_C#_.net_Winforms_Progress Bar - Fatal编程技术网

C# winforms中进度条的使用

C# winforms中进度条的使用,c#,.net,winforms,progress-bar,C#,.net,Winforms,Progress Bar,我只是想让进度条前进一步,因为计时器在一秒钟内滴答作响,但无法做到这一点。请帮忙 我应该在计时器的滴答声事件中使用变量i和增量i乘以1吗。 写:progressBar1.Increment(i)——我尝试了这个,它成功了 但是为什么它不能使用以下代码: public partial class Form1 : Form { Timer t = new Timer(); public Form1() { InitializeComponent();

我只是想让进度条前进一步,因为计时器在一秒钟内滴答作响,但无法做到这一点。请帮忙

我应该在计时器的滴答声事件中使用变量i和增量i乘以1吗。 写:progressBar1.Increment(i)——我尝试了这个,它成功了

但是为什么它不能使用以下代码:

public partial class Form1 : Form
{
    Timer t = new Timer();

    public Form1()
    {
        InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        t.Interval = 1000;
        t.Enabled = true;
        t.Tick += new EventHandler(t_Tick);
    }
    void t_Tick(object sender, EventArgs e)
    {
        progressBar1.Increment(1);
    }
当一秒钟过去时,滴答声事件发生,progressBar应该增加1,但在这里,它只是在一个增量上卡住,即它只增加1,然后停止。

。分配事件处理程序后,尝试启用计时器:

private void Form1_Load(object sender, EventArgs e)
{
    t.Interval = 1000;
    t.Tick += new EventHandler(t_Tick);
    t.Enabled = true;
}

缺少计时器启动,下面的代码假定正常工作

public partial class Form1 : Form
{
    Timer t = new Timer();

    public Form1()
    {
        InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        t.Interval = 1000;
        t.Tick += new EventHandler(t_Tick);
        // enable timer after the handler attached
        t.Enabled = true;
        // Start the timer.
        t.Start();
    }
    void t_Tick(object sender, EventArgs e)
    {
        progressBar1.Increment(1);
    }

您的代码可能正在运行。问题是进度条上的最大值可能太高,以至于进度条的值需要一段时间才能高到足以显示下一个块


将最大值设置为100,您应该可以看到您的代码运行良好。

最好先添加处理程序,然后设置enabled=truel。我尝试过了,代码正常运行。progressbar的最小值和最大值是多少?-1:。先生,你能告诉我这是如何工作的吗?我的意思是,什么时候触发勾号事件?当t.Enabled设置为true或else时?为什么在事件处理程序之前启用计时器时它不起作用?请用简单的语言举例说明maximun和minimum属性?