Create Progress bar in windows application
By Perry
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
Popularity (6975 Views)
Article Discussion: Create Progress bar in windows application
Perry posted at Friday, October 17, 2008 10:19 AM
deepak replied
to Perry at Friday, October 17, 2008 1:15 PM
hi Megha,
I want progress bar for an event, that will interact with database and get required data. I want to have a progress bar such that, the event will be working in background but with rogress bar has to progress simultaneously.
Thank in advance.