Export (0) Print
Expand All

ProgressBar.Value Property

Gets or sets the current position of the progress bar.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[BindableAttribute(true)] 
public int Value { get; set; }
/** @property */
public int get_Value ()

/** @property */
public void set_Value (int value)

public function get Value () : int

public function set Value (value : int)

Property Value

The position within the range of the progress bar. The default is 0.

Exception typeCondition

ArgumentException

The value specified is greater than the value of the Maximum property.

-or-

The value specified is less than the value of the Minimum property.

The minimum and maximum values of the Value property are specified by the Minimum and Maximum properties. This property enables you to increment or decrement the value of the progress bar directly. To perform consistent increases in the value of the ProgressBar control you can use the Step property with the PerformStep method. To increase the progress bar value by varying amounts, use the Increment method.

The following code example demonstrates how to use the Increment method and the Value property to increment the value of a ProgressBar in the Tick event of a Timer. The example also displays the Value property in a StatusBarPanel to provide a textual representation of the ProgressBar. This example requires that you have a ProgressBar control, named progressBar1, and a StatusBar control that contains a StatusBarPanel, named statusBarPanel1. The Timer, named time, must be added to the form as a member.

private Timer time = new Timer();

// Call this method from the constructor of the form.
private void InitializeMyTimer()
{
   // Set the interval for the timer.
   time.Interval = 250;
   // Connect the Tick event of the timer to its event handler.
   time.Tick += new EventHandler(IncreaseProgressBar);
   // Start the timer.
   time.Start();
}

private void IncreaseProgressBar(object sender, EventArgs e)
{
   // Increment the value of the ProgressBar a value of one each time.
   progressBar1.Increment(1);
   // Display the textual value of the ProgressBar in the StatusBar control's first panel.
   statusBarPanel1.Text = progressBar1.Value.ToString() + "% Completed";
   // Determine if we have completed by comparing the value of the Value property to the Maximum value.
   if (progressBar1.Value == progressBar1.Maximum)
      // Stop the timer.
      time.Stop();
}

private Timer time = new Timer();

// Call this method from the constructor of the form.
private void InitializeMyTimer()
{
    // Set the interval for the timer.
    time.set_Interval(250);
    // Connect the Tick event of the timer to its event handler.
    time.add_Tick(new EventHandler(IncreaseProgressBar));
    // Start the timer.
    time.Start();
} //InitializeMyTimer

private void IncreaseProgressBar(Object sender, EventArgs e)
{
    // Increment the value of the ProgressBar a value of one each time.
    progressBar1.Increment(1);
    // Display the textual value of the ProgressBar in the StatusBar
    // control's first panel.
    statusBarPanel1.set_Text(progressBar1.get_Value() + "% Completed");
    // Determine if we have completed by comparing the value of the Value
    // property to the Maximum value.
    if (progressBar1.get_Value() == progressBar1.get_Maximum()) {
        // Stop the timer.
        time.Stop();
    }        
} //IncreaseProgressBar

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft