ProgressBar.Maximum 属性

获取或设置控件范围的最大值。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property Maximum As Integer
用法
Dim instance As ProgressBar
Dim value As Integer

value = instance.Maximum

instance.Maximum = value
public int Maximum { get; set; }
public:
property int Maximum {
    int get ();
    void set (int value);
}
/** @property */
public int get_Maximum ()

/** @property */
public void set_Maximum (int value)
public function get Maximum () : int

public function set Maximum (value : int)

属性值

范围的最大值。默认值为 100。

异常

异常类型 条件

ArgumentException

指定的值小于 0。

备注

此属性指定 Value 属性的上限。当 Maximum 属性的值更改时,将重绘 ProgressBar 控件以反映该控件的新范围。当 Value 属性的值等于 Maximum 属性的值时,进度栏被完全填满。

可以使用此属性指定一个值,Value 属性必须设置为此值(通过设置 Value 属性或使用 IncrementPerformStep 方法)来指示操作已完成。例如,可以将 Maximum 属性的值设置为文件复制操作中文件的总数。每次复制一个文件后 Value 属性都加 1,直到复制完所有文件为止。此时,进度栏将完全填满。

示例

下面的代码示例使用 ProgressBar 控件来显示文件复制操作的进度。该示例使用 MinimumMaximum 属性指定 ProgressBar 的范围,它等效于要复制的文件数。代码还将 Step 属性用于 PerformStep 方法以在复制文件时增加 ProgressBar 的值。此示例要求已在 Form 中创建了名为 pBar1ProgressBar 控件,并且还创建了执行文件复制操作的名为 CopyFile 的方法(它返回一个布尔值,指示文件复制操作已成功完成)。此代码还要求已创建包含要复制的文件的字符串数组,并已将其传递给示例中定义的 CopyWithProgress 方法,而且要求该方法从 Form 中的另一个方法或事件进行调用。

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
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:
   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.set_Visible(true);
    // Set Minimum to 1 to represent the first file being copied.
    pBar1.set_Minimum(1);
    // Set Maximum to the total number of files to copy.
    pBar1.set_Maximum(fileNames.get_Length());
    // Set the initial value of the ProgressBar.
    pBar1.set_Value(1);
    // Set the Step property to a value of 1 to represent each file
    // being copied.
    pBar1.set_Step(1);
    // Loop through all files to copy.
    for (int x = 1; x <= fileNames.get_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();
        }
    }
} //CopyWithProgress

平台

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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

ProgressBar 类
ProgressBar 成员
System.Windows.Forms 命名空间
Minimum
Value