Windows应用程序中的进度条控件 [英] progress bar control in windows application

查看:90
本文介绍了Windows应用程序中的进度条控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在使用visual studio 2010的Windows应用程序中有一个进度条控件。

它将是可见= false默认情况下。单击提交按钮后,它需要显示,并且需要在屏幕上显示进度。

我在谷歌搜索但我无法获得正确的解决方案。

请帮我找到解决方案。

Hi,

I have a progress bar control in an windows application using visual studio 2010.
It will be "visible = false" by default. upon clicking on submit button it need to be visible and progress need to be shown on the screen.
I have searched in google but I couldn't get the correct solution.
please help me finding the solution.

推荐答案

using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, System.EventArgs e)
    {
        // Start the BackgroundWorker.
        backgroundWorker1.RunWorkerAsync();
    }

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        for (int i = 1; i <= 100; i++)
        {
        // Wait 100 milliseconds.
        Thread.Sleep(100);
        // Report progress.
        backgroundWorker1.ReportProgress(i);
        }
    }

    private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        // Change the value of the ProgressBar to the BackgroundWorker progress.
        progressBar1.Value = e.ProgressPercentage;
        // Set the text.
        this.Text = e.ProgressPercentage.ToString();
    }
    }
}





更多详情访问下面的网页...

http://www.dotnetperls.com/progressbar [ ^ ]


这就是我在dotnet上做的事情3.5



This is what i do on dotnet 3.5

using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
    public Form1()
    {
        InitializeComponent();
    }

private delegate void progressDelegate(string progress);

    private void Form1_Load(object sender, System.EventArgs e)
    {
        // Start the BackgroundWorker.
        ProgressBar1.Visible = true;
        backgroundWorker1.RunWorkerAsync();
    }

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
       for (int i = 0; i <= 50000; i++)
               {
            progressDelegate m_UpdateText = null;
            m_UpdateText = new progressDelegate(progress1);
            this.Invoke(m_UpdateText, i.ToString());
        }
    }


    private void progress1(string progress)
    {
        this.Text = progress;
        ProgressBar1.Minimum = 0;
        ProgressBar1.Maximum = 50000;
        ProgressBar1.Value = Convert.ToInt32(progress);
    }

    private void BackgroundWorker1_RunWorkerCompleted(object sender,   System.ComponentModel.RunWorkerCompletedEventArgs e)
    {
        Interaction.MsgBox("Done proccessing");
                this.Text = "Done";
        ProgressBar1.Visible = false;
    }

}


private void btn_Submit_Click(object sender,EventArgs e)

{

Progressbar1.Visible = True;

//这里你的代码

}
private void btn_Submit_Click(object sender, EventArgs e)
{
Progressbar1.Visible=True;
//here ur code
}


这篇关于Windows应用程序中的进度条控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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