如何设置进度条的值 [英] How to set value of progress bar

查看:543
本文介绍了如何设置进度条的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用C#编写的WinForms用户控件。在用户控制,我有三个文本框:




  • txtStartNumber - 输入类型:INT

  • txtEndNumber - 输入类型:int类型。

  • txtQuantity - iput的类型为:int类型。 (值= txtEndNumber - txtStartNumber)



进度条表示没有。的记录添加到数据库和它的总范围被设定为等于txtQuantity



当一个或多个记录重复的,进度条被停止。

我的问题是:




  1. 如何设置进度条的初始值

  2. 如何管理进度条显示的进度?



我如何将它保存到数据库

 为(长I =从; I<到;我++)
{
为( INT J = 0; J<(来 - 从); J ++)
{
arrCardNum [J] =从+ J;
串R = arrCardNum [J]的ToString();
尝试
{
sp.SaveCards(R,2,card_Type_ID,SaveDate,2);
progressBar1.Value = j的;
}
}
}


解决方案

试试这个:

 私人无效StartBackgroundWork(){
如果(Application.RenderWithVisualStyles)
progressBar.Style = ProgressBarStyle.Marquee;
,否则{
progressBar.Style = ProgressBarStyle.Continuous;
progressBar.Maximum = 100;
progressBar.Value = 0;
timer.Enabled = TRUE;
}
backgroundWorker.RunWorkerAsync();
}

私人无效timer_Tick(对象发件人,EventArgs五){
progressBar.Value + = 5;
如果(progressBar.Value&≥120)
progressBar.Value = 0;
}



选取框风格需要VISUALSTYLES启用,但它自身的持续滚动而无需进行更新。我利用它来进行数据库操作不报告其进展情况。



下面是另一个进度条教程


I have written a user control using C# Winforms. In the user control, I have three textboxes:

  • txtStartNumber - input is of type: int.
  • txtEndNumber - input is of type: int.
  • txtQuantity - iput is of type: int. (value = txtEndNumber - txtStartNumber)

The progress bar denotes the no. of records added to the database and its total range is set to be equal to txtQuantity.

When one or more records are duplicate, the progress bar is stopped.

My questions are:

  1. How to set the initial value of the progress bar?
  2. How to manage the progress shown by progress bar?

How I save it to the database:

for (long i = from; i < to; i++)
{
    for (int j = 0; j < (to - from); j++)
    {
        arrCardNum[j] = from + j;
        string r = arrCardNum[j].ToString();
        try
        {
            sp.SaveCards(r, 2, card_Type_ID, SaveDate, 2);
            progressBar1.Value = j;
        }
    }
}

解决方案

Try this:

private void StartBackgroundWork() {
    if (Application.RenderWithVisualStyles)
        progressBar.Style = ProgressBarStyle.Marquee;
    else {
        progressBar.Style = ProgressBarStyle.Continuous;
        progressBar.Maximum = 100;
        progressBar.Value = 0;
        timer.Enabled = true;
    }
    backgroundWorker.RunWorkerAsync();
}

private void timer_Tick(object sender, EventArgs e) {
    progressBar.Value += 5;
    if (progressBar.Value > 120)
        progressBar.Value = 0;
}

The Marquee style requires VisualStyles to be enabled, but it continuously scrolls on its own without needing to be updated. I use that for database operations that don't report their progress.

Here is another Progress Bar Tutorial

这篇关于如何设置进度条的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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