ProgressBar.Maximum ProgressBar.Maximum ProgressBar.Maximum ProgressBar.Maximum Property

定义

获取或设置控件范围的最大值。Gets or sets the maximum value of the range of the control.

public:
 property int Maximum { int get(); void set(int value); };
public int Maximum { get; set; }
member this.Maximum : int with get, set
Public Property Maximum As Integer

属性值

范围的最大值。The maximum value of the range. 默认值为 100。The default is 100.

异常

指定的值小于 0。The value specified is less than 0.

示例

下面的代码示例使用ProgressBar控件显示文件复制操作的进度。The following code example uses a ProgressBar control to display the progress of a file copy operation. 该示例使用MinimumMaximum属性来ProgressBar指定的范围, 该范围等效于要复制的文件数。The example uses the Minimum and Maximum properties to specify a range for the ProgressBar that is equivalent to the number of files to copy. 此代码还将Step属性PerformStep与方法一起使用, 以在复制文件时ProgressBar递增的值。The code also uses the Step property with the PerformStep method to increment the value of the ProgressBar as a file is copied. ProgressBar此示例要求你创建一个名pBar1Form的控件, 该控件是在中创建的, 并且已创建一个CopyFile名为的方法 (该方法返回一个布尔值, 指示文件复制操作是已成功完成) 执行文件复制操作。This example requires that you have a ProgressBar control created called pBar1 that is created within a Form and that there is a method created called CopyFile (that returns a Boolean value indicating the file copy operation was completed successfully) that performs the file copy operation. 此代码还要求创建包含要复制的文件的字符串数组, 并将其传递CopyWithProgress给在此示例中定义的方法, 并且该方法是从Form中的其他方法或事件调用的。The code also requires that an array of strings containing the files to copy is created and passed to the CopyWithProgress method defined in the example and that the method is called from another method or event in the Form.

private:
   void CopyWithProgress( array<String^>^filenames )
   {
      // Display the ProgressBar control.
      pBar1->Visible = true;

      // Set Minimum to 1 to represent the first file being copied.
      pBar1->Minimum = 1;

      // Set Maximum to the total number of files to copy.
      pBar1->Maximum = filenames->Length;

      // Set the initial value of the ProgressBar.
      pBar1->Value = 1;

      // Set the Step property to a value of 1 to represent each file being copied.
      pBar1->Step = 1;

      // Loop through all files to copy.
      for ( int x = 1; x <= filenames->Length; x++ )
      {
         // Copy the file and increment the ProgressBar if successful.
         if ( CopyFile( filenames[ x - 1 ] ) == true )
         {
            // Perform the increment on the ProgressBar.
            pBar1->PerformStep();
         }
      }
   }
private void CopyWithProgress(string[] filenames)
{
	// Display the ProgressBar control.
	pBar1.Visible = true;
	// Set Minimum to 1 to represent the first file being copied.
	pBar1.Minimum = 1;
	// Set Maximum to the total number of files to copy.
	pBar1.Maximum = filenames.Length;
	// Set the initial value of the ProgressBar.
	pBar1.Value = 1;
	// Set the Step property to a value of 1 to represent each file being copied.
	pBar1.Step = 1;
	
	// Loop through all files to copy.
	for (int x = 1; x <= filenames.Length; x++)
	{
		// Copy the file and increment the ProgressBar if successful.
		if(CopyFile(filenames[x-1]) == true)
		{
			// Perform the increment on the ProgressBar.
			pBar1.PerformStep();
		}
	}
}
Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
    ' Display the ProgressBar control.
    pBar1.Visible = True
    ' Set Minimum to 1 to represent the first file being copied.
    pBar1.Minimum = 1
    ' Set Maximum to the total number of files to copy.
    pBar1.Maximum = filenames.Length
    ' Set the initial value of the ProgressBar.
    pBar1.Value = 1
    ' Set the Step property to a value of 1 to represent each file being copied.
    pBar1.Step = 1

    ' Loop through all files to copy.
    Dim x As Integer
    for x = 1 To filenames.Length - 1
        ' Copy the file and increment the ProgressBar if successful.
        If CopyFile(filenames(x - 1)) = True Then
            ' Perform the increment on the ProgressBar.
            pBar1.PerformStep()
        End If
    Next x
End Sub

注解

此属性指定Value属性的上限。This property specifies the upper limit of the Value property. Maximum属性的值更改时ProgressBar , 将重新绘制控件以反映控件的新范围。When the value of the Maximum property is changed, the ProgressBar control is redrawn to reflect the new range of the control. Value属性的值等于Maximum属性的值时, 将完全填充进度栏。When the value of the Value property is equal to the value of the Maximum property, the progress bar is completely filled.

您可以使用此属性来指定Value一个值, 属性必须设置为此值 (通过Value设置属性或使用IncrementPerformStep方法) 指示操作已完成。You can use this property to specify a value to which the Value property must be set (by setting the Value property or using the Increment or PerformStep methods) to indicate that an operation is complete. 例如, 可以将Maximum属性的值设置为文件复制操作中的文件总数。For example, you can set the value of the Maximum property to the total number of files in a file copy operation. 每次复制文件时, 都可以Value将属性增加 1, 直到复制文件总数。Each time a file is copied, the Value property can be increased by 1 until the total number of files is copied. 此时, 将完全填充进度栏。At that point, the progress bar would be completely filled.

适用于

另请参阅