logo

Create Progress bar in windows application

By Raj Cool...
Printer Friendly Version
View My Articles
598 Views
    

I have written very big application where I am displaying the dialog box and connection is establishing in background and user can see in the status bar whats going on like 'Connecting to server XXX'...'sending password'...'connection rejected so trying to other server'...and at last 'Ready' message will be displayed in the status bar.


Steps to create ProgressBar:
----------------------------

Create Color fade busy bar using

private System.Windows.Forms.BusyBar.ColorFadeBusyBar progressBar;
add it to your initialize component

this.progressBar = new System.Windows.Forms.BusyBar.ColorFadeBusyBar();

This will auto generate while you create the component. Set the properties

this.progressBar.BackColor = System.Drawing.SystemColors.Control;
this.progressBar.BorderStyle3D = System.Windows.Forms.Border3DStyle.SunkenInner;
this.progressBar.Color2 = System.Drawing.SystemColors.Control;
this.progressBar.FadeLength = -30;
this.progressBar.ForeColor = System.Drawing.SystemColors.Highlight;
this.progressBar.Location = new System.Drawing.Point(191, 3);
this.progressBar.Name = "progressBar";
this.progressBar.PingPong = true;
this.progressBar.ShowBorder = true;
this.progressBar.Size = new System.Drawing.Size(86, 18);
this.progressBar.StepSize = 1;
this.progressBar.StepTimeout = 25;
this.progressBar.TabIndex = 65;
this.progressBar.Visible = false;

///
/// This method starts the progress bar
///
private void StartProgress() {
    progressBar.Show();
    progressBar.Start();
}

///
/// This method stops the progress bar
///
private void StopProgress() {
    progressBar.Hide();
    progressBar.Stop();
}

At last you will need thread process which writes and call this start and stop methods,.

///
/// This method starts a thread for reading the output from the transport
///

private void WaitingThread() {
    //Thread waiting for the output stream of the process
    StartProgress();
    int TimeOutPeriod = 30; //sec
    DateTime expireTime = DateTime.Now.AddSeconds(TimeOutPeriod);
    outputThread = new Thread(new ThreadStart(ReadFromLoginOutput));
    isApplicationTimedOut = false;
    outputThread.Start();
    while (outputThread.IsAlive && outputThread.ThreadState !=              System.Threading.ThreadState.AbortRequested) {
        Thread.Sleep(100);

      if(TimeOuPeriodt > 0) && (DateTime.Compare(expireTime, DateTime.Now) < 0)) {
        outputThread.Abort();
        isApplicationTimedOut = true;
      }
      Application.DoEvents();
      }
     StopProgress();
}

you can fetch the output from standard output in ReadfromLoginOutput method.

Regards,
Megha



Didn't Find The Answer You Were Looking For?

EggHeadCafe has experts online right now that may know the answer to your question.  We pay them a bonus for answering as many questions as they can.  So, why not help them and yourself by becoming a member (free) and ask them your question right now?
Ask Question In Live Forum

If you have an OpenID and do not want to become a member of the EggHeadCafe forum, you can also sign on to Chat Chaos and post your question to our real time Silverlight chat application.
Ask Question In Chat Chaos

Article Discussion: Create Progress bar in windows application
Raj Cool... posted at Friday, October 17, 2008 10:19 AM
Original Article
 






  $1000 Contest    [)ia6l0 iii - $228  |  Jonathan VH - $161  |  Huggy Bear - $135  |  F Cali - $95  |  egg egg - $94  |  more Advertise  |  Privacy  |   (c) 2010