Aracılığıyla paylaş


ProgressBar.PerformStep Yöntem

Tanım

İlerleme çubuğunun geçerli konumunu özelliğin miktarına göre ilerletir Step .

public:
 void PerformStep();
public void PerformStep();
member this.PerformStep : unit -> unit
Public Sub PerformStep ()

Özel durumlar

Örnekler

Aşağıdaki kod örneği, bir ProgressBar dosya kopyalama işleminin ilerleme durumunu görüntülemek için bir denetim kullanır. Örnek, kopyalanacak dosya sayısına eşdeğer bir aralık belirtmek için ProgressBar ve Maximum özelliklerini kullanırMinimum. Kod, dosyasının Step kopyalandığında değerini ProgressBar artırmak için yöntemiyle özelliğini PerformStep de kullanır. Bu örnek, içinde oluşturulan adlı pBar1 bir ProgressBarFormdenetimin oluşturulmasını ve dosya kopyalama işlemini gerçekleştiren adlı CopyFile bir yöntemin (dosya kopyalama işleminin başarıyla tamamlandığını belirten boole değeri döndüren) olmasını gerektirir. Kod ayrıca kopyalanacak dosyaları içeren bir dizi dizenin oluşturulmasını ve örnekte tanımlanan yönteme geçirilmesini CopyWithProgress ve yönteminin içinde Formbaşka bir yöntemden veya olaydan çağrılmış olmasını gerektirir.

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

Açıklamalar

yöntemi, PerformStep ilerleme çubuğunun değerini özelliği tarafından belirtilen miktara Step kadar artırır. bir işlemdeki Step tamamlanan her görevin ilerleme çubuğunun değerini değiştireceğini belirtmek için özelliğini kullanabilirsiniz. Örneğin, bir dosya grubunu kopyaladığınızda, özelliğin Step değerini 1, özelliğinin Maximum değerini de kopyalanacak toplam dosya sayısına ayarlamak isteyebilirsiniz. Her dosya kopyalandığında, ilerleme çubuğunu özelliğin PerformStep değerine Step göre artırmak için yöntemini çağırabilirsiniz. İlerleme çubuğunun değeri konusunda daha esnek bir denetime sahip olmak istiyorsanız yöntemini kullanabilir Increment veya özelliğin Value değerini doğrudan ayarlayabilirsiniz.

özelliği geçerli Value konumunu ProgressBarbelirtir. yöntemi çağrıldıktan PerformStep sonra özelliği özelliğin Value değerinden Maximum büyükse, Value özellik özelliğin Maximum değerinde kalır. yöntemi içinde PerformStep belirtilen StepValue negatif bir değerle çağrıldıktan sonra özelliği özelliğin değerinden Minimum küçükse, Value özellik özelliğin Minimum değerinde kalır.

Stili yerine sürekli kaydırma çubuğu Valuegörüntüleyecek şekilde ayarlanmış Marquee bir ProgressBar nesne için çağrısı PerformStep gereksizdir ve bir InvalidOperationExceptionoluşturur.

Şunlara uygulanır

Ayrıca bkz.