다음을 통해 공유


ProgressBar 클래스

Windows ProgressBar 컨트롤을 나타냅니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class ProgressBar
    Inherits Control
‘사용 방법
Dim instance As ProgressBar
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class ProgressBar : Control
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class ProgressBar : public Control
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class ProgressBar extends Control
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class ProgressBar extends Control

설명

ProgressBar 컨트롤은 시간이 많이 걸리는 작업의 진행률을 다음의 세 가지 스타일 중 하나로 시각적으로 나타냅니다.

  • 단계적으로 왼쪽에서 오른쪽으로 늘어나는 세그먼트로 구분된 블록

  • 왼쪽에서 오른쪽으로 채워지는 연속 막대

  • ProgressBar에서 움직이는 텍스트 방식으로 스크롤되는 블록

Style 속성은 표시되는 ProgressBar의 스타일을 결정합니다. ProgressBar 컨트롤은 가로 방향으로만 설정할 수 있습니다. 세로 방향 ProgressBar를 만드는 방법을 보여 주는 예제를 보려면 ProgressBarRenderer 클래스를 참조하십시오. ProgressBar 컨트롤은 일반적으로 응용 프로그램이 파일 복사나 문서 인쇄 같은 작업을 수행할 때 사용됩니다. 표시 큐가 없으면 응용 프로그램이 응답하지 않는 것으로 사용자가 생각할 수도 있습니다. 응용 프로그램에서 ProgressBar를 표시함으로써 응용 프로그램이 긴 작업을 수행하고 있고 계속 응답을 하고 있다는 것을 사용자에게 알릴 수 있습니다.

MaximumMinimum 속성은 작업의 진행률을 나타내는 값 범위를 정의합니다. 일반적으로 Minimum 속성에는 0이 설정되고 Maximum 속성에는 작업 완료를 나타내는 값이 설정됩니다. 예를 들어, 여러 파일을 복사하는 동안 진행률을 표시하는 경우 Maximum 속성을 복사할 총 파일 수로 설정할 수 있습니다.

Value 속성은 작업을 완료할 때까지의 응용 프로그램 진행률을 나타냅니다. ProgressBar에 표시되는 값은 Value 속성의 현재 값을 대략적으로 나타냅니다. Value 속성은 ProgressBar의 크기를 기반으로 하여 다음 블록을 표시하거나 막대의 크기를 늘려야 하는 시기를 결정합니다.

Value 속성을 직접 변경하는 것 외에도 ProgressBar를 통해 표시되는 값을 수정할 수 있는 여러 방법이 있습니다. Step 속성을 사용하여 Value 속성이 특정 값만큼 증분되도록 지정한 다음 PerformStep 메서드를 호출하여 값을 증분시킬 수 있습니다. 증분 값을 변경하려면 Increment 메서드를 사용하고 Value 속성을 증분시킬 값의 양을 지정합니다.

참고

비주얼 스타일을 Windows XP Home Edition, Windows XP Professional, Windows Server 2003 이상에서 사용하는 경우 ProgressBarForeColor 변경 사항은 적용되지 않습니다.

예제

다음 코드 예제에서는 ProgressBar 컨트롤을 사용하여 파일 복사 작업의 진행률을 표시합니다. 예제에서는 MinimumMaximum 속성을 사용하여 복사할 파일 수와 일치하도록 ProgressBar의 범위를 지정합니다. 또한 PerformStep 메서드와 함께 Step 속성을 사용하여 파일 복사가 진행되는 동안 ProgressBar의 값을 증분시킵니다. 이 예제를 실행하려면 FormpBar1이라는 ProgressBar 컨트롤이 있고, 파일 복사 작업을 수행하는 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

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.ProgressBar

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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 멤버
System.Windows.Forms 네임스페이스