Wednesday, October 27, 2010

Use of Progress Bar control in C#

A Progress Bar control is used to display the progress of some activity.

The project is developed using C#, Windows Forms, and Visual Studio 2005.

As you can see below, we can add a timer control to the form and on the timer tick event handler, we can increment the value of the progress bar.

namespace Progress_Bar

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}



// Call the function of tick event of the timer:_...

// Set the timer Intervel at 60:_

// Set the timer enabled "True" by the timer properties:_

private void timer1_Tick(object sender, EventArgs e)

{

fn_prbar_();
}



//Create the function for progress bar:_
public void fn_prbar_()

{
progressBar1.Increment(1);

label1.Text = "Connecting to server_ " + progressBar1.Value.ToString() + "%";

if (progressBar1.Value == progressBar1.Maximum)

{
timer1.Stop();

MessageBox.Show("Server has been connected");
this.Close();
timer1.Stop();

}
}

}

}

No comments:

Post a Comment