Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Jean A Brandelero 24-Jul-13 8:36am    
Wath you are doing in your "progress"? Just make it visible, and do pb.PerformStep()

C#
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();
    }
    }
}


for More Detail visit on belowing web page...
http://www.dotnetperls.com/progressbar[^]
 
Share this answer
 
This is what i do on dotnet 3.5

C#
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;
    }

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900