ProgressBar.Step Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает или задает сумму, на которую вызов PerformStep() метода увеличивает текущее положение индикатора выполнения.
public:
property int Step { int get(); void set(int value); };
public int Step { get; set; }
member this.Step : int with get, set
Public Property Step As Integer
Значение свойства
Сумма, по которой необходимо увеличить индикатор хода выполнения с каждым вызовом PerformStep() метода. По умолчанию используется значение 10.
Примеры
В следующем примере кода используется ProgressBar элемент управления для отображения хода выполнения операции копирования файлов. В примере используются Minimum свойства и Maximum свойства для указания диапазона, эквивалентного количеству файлов для ProgressBar копирования. Код также использует Step свойство с PerformStep методом для увеличения значения ProgressBar файла в виде файла. В этом примере требуется, чтобы у вас был ProgressBar созданный элемент pBar1 управления, созданный в объекте Form, и что создан метод CopyFile (возвращающий логическое значение, указывающее, что операция копирования файлов была завершена успешно) которая выполняет операцию копирования файлов. Код также требует, чтобы массив строк, содержащих файлы для копирования, был создан и передан CopyWithProgress в метод, определенный в примере, и что метод вызывается из другого метода или события в примере 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 ] ))
{
// 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]))
{
// 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
Комментарии
Свойство можно использовать Step для указания суммы, которую каждая завершенная задача в операции изменяет значение индикатора выполнения. Например, если вы копируете группу файлов, может потребоваться задать для свойства значение Step 1, а значение Maximum свойства — общее количество файлов для копирования. При копировании каждого файла можно вызвать PerformStep метод, чтобы увеличить индикатор хода выполнения по значению Step свойства. Если требуется более гибкий контроль над значением индикатора выполнения, можно использовать Increment метод или задать значение Value свойства напрямую.