ProgressBarRenderer 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
비주얼 스타일을 사용하여 진행률 표시줄 컨트롤을 렌더링하는 데 사용되는 메서드를 제공합니다. 이 클래스는 상속할 수 없습니다.
public ref class ProgressBarRenderer sealed
public ref class ProgressBarRenderer abstract sealed
public sealed class ProgressBarRenderer
public static class ProgressBarRenderer
type ProgressBarRenderer = class
Public NotInheritable Class ProgressBarRenderer
Public Class ProgressBarRenderer
- 상속
-
ProgressBarRenderer
예제
다음 코드 예제에서는 세로 진행률 표시줄을 그리기 위해 메서드를 DrawVerticalChunks 사용하는 DrawVerticalBar 사용자 지정 컨트롤을 만드는 방법을 보여 줍니다. 컨트롤은 1초마다 추가된 조각으로 진행률 표시줄을 다시 그리는 데 사용합니다 Timer . 메서드는 SetupProgressBarChunkThickness 및 ChunkSpaceThickness 속성을 사용하여 그려지는 각 점진적으로 더 큰 사각형의 높이를 계산합니다.
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::VisualStyles;
namespace ProgressBarRendererSample
{
public ref class VerticalProgressBar : public Control
{
private:
int numberChunksValue;
int ticks;
Timer^ progressTimer;
array<Rectangle>^ progressBarRectangles;
public:
VerticalProgressBar() : Control()
{
this->Location = Point(10, 10);
this->Width = 50;
progressTimer = gcnew Timer();
// The progress bar will update every second.
progressTimer->Interval = 1000;
progressTimer->Tick += gcnew EventHandler(this,
&VerticalProgressBar::progressTimer_Tick);
// This property also calls SetupProgressBar to initialize
// the progress bar rectangles if styles are enabled.
NumberChunks = 20;
// Set the default height if visual styles are not enabled.
if (!ProgressBarRenderer::IsSupported)
{
this->Height = 100;
}
}
// Specify the number of progress bar chunks to base the height on.
public:
property int NumberChunks
{
int get()
{
return numberChunksValue;
}
void set(int value)
{
if (value <= 50 && value > 0)
{
numberChunksValue = value;
}
else
{
MessageBox::Show("Number of chunks must be between " +
"0 and 50; defaulting to 10");
numberChunksValue = 10;
}
// Recalculate the progress bar size, if visual styles
// are active.
if (ProgressBarRenderer::IsSupported)
{
SetupProgressBar();
}
}
}
// Draw the progress bar in its normal state.
protected:
virtual void OnPaint(PaintEventArgs^ e) override
{
__super::OnPaint(e);
if (ProgressBarRenderer::IsSupported)
{
ProgressBarRenderer::DrawVerticalBar(e->Graphics,
ClientRectangle);
this->Parent->Text = "VerticalProgressBar Enabled";
}
else
{
this->Parent->Text = "VerticalProgressBar Disabled";
}
}
// Initialize the rectangles used to paint the states of the
// progress bar.
private:
void SetupProgressBar()
{
if (!ProgressBarRenderer::IsSupported)
{
return;
}
// Determine the size of the progress bar frame.
this->Size = System::Drawing::Size(ClientRectangle.Width,
(NumberChunks * (ProgressBarRenderer::ChunkThickness +
(2 * ProgressBarRenderer::ChunkSpaceThickness))) + 6);
// Initialize the rectangles to draw each step of the
// progress bar.
progressBarRectangles = gcnew array<Rectangle>(NumberChunks);
for (int i = 0; i < NumberChunks; i++)
{
// Use the thickness defined by the current visual style
// to calculate the height of each rectangle. The size
// adjustments ensure that the chunks do not paint over
// the frame.
int filledRectangleHeight =
((i + 1) * (ProgressBarRenderer::ChunkThickness +
(2 * ProgressBarRenderer::ChunkSpaceThickness)));
progressBarRectangles[i] = Rectangle(
ClientRectangle.X + 3,
ClientRectangle.Y + ClientRectangle.Height - 3
- filledRectangleHeight,
ClientRectangle.Width - 6,
filledRectangleHeight);
}
}
// Handle the timer tick; draw each progressively larger rectangle.
private:
void progressTimer_Tick(Object^ myObject, EventArgs^ e)
{
if (ticks < NumberChunks)
{
Graphics^ g = this->CreateGraphics();
ProgressBarRenderer::DrawVerticalChunks(g,
progressBarRectangles[ticks]);
ticks++;
}
else
{
progressTimer->Enabled = false;
}
}
// Start the progress bar.
public:
void Start()
{
if (ProgressBarRenderer::IsSupported)
{
progressTimer->Start();
}
else
{
MessageBox::Show("VerticalScrollBar requires visual styles");
}
}
};
public ref class Form1 : public Form
{
private:
VerticalProgressBar^ bar1;
Button^ button1;
public:
Form1() : Form()
{
this->Size = System::Drawing::Size(500, 500);
bar1 = gcnew VerticalProgressBar();
bar1->NumberChunks = 30;
button1 = gcnew Button();
button1->Location = Point(150, 10);
button1->Size = System::Drawing::Size(150, 30);
button1->Text = "Start VerticalProgressBar";
button1->Click += gcnew EventHandler(this, &Form1::button1_Click);
Controls->AddRange(gcnew array<Control^> { button1, bar1 });
}
// Start the VerticalProgressBar.
private:
void button1_Click(Object^ sender, EventArgs^ e)
{
bar1->Start();
}
};
}
[STAThread]
int main()
{
// The call to EnableVisualStyles below does not affect
// whether ProgressBarRenderer.IsSupported is true; as
// long as visual styles are enabled by the operating system,
// IsSupported is true.
Application::EnableVisualStyles();
Application::Run(gcnew ProgressBarRendererSample::Form1());
}
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace ProgressBarRendererSample
{
public class Form1 : Form
{
private VerticalProgressBar bar1 = new VerticalProgressBar();
private Button button1 = new Button();
public Form1()
: base()
{
this.Size = new Size(500, 500);
bar1.NumberChunks = 30;
button1.Location = new Point(150, 10);
button1.Size = new Size(150, 30);
button1.Text = "Start VerticalProgressBar";
button1.Click += new EventHandler(button1_Click);
Controls.AddRange(new Control[] { button1, bar1 });
}
[STAThread]
public static void Main()
{
// The call to EnableVisualStyles below does not affect
// whether ProgressBarRenderer.IsSupported is true; as
// long as visual styles are enabled by the operating system,
// IsSupported is true.
Application.EnableVisualStyles();
Application.Run(new Form1());
}
// Start the VerticalProgressBar.
private void button1_Click(object sender, EventArgs e)
{
bar1.Start();
}
}
public class VerticalProgressBar : Control
{
private int numberChunksValue;
private int ticks;
private Timer progressTimer = new Timer();
private Rectangle[] progressBarRectangles;
public VerticalProgressBar()
: base()
{
this.Location = new Point(10, 10);
this.Width = 50;
// The progress bar will update every second.
progressTimer.Interval = 1000;
progressTimer.Tick += new EventHandler(progressTimer_Tick);
// This property also calls SetupProgressBar to initialize
// the progress bar rectangles if styles are enabled.
NumberChunks = 20;
// Set the default height if visual styles are not enabled.
if (!ProgressBarRenderer.IsSupported)
{
this.Height = 100;
}
}
// Specify the number of progress bar chunks to base the height on.
public int NumberChunks
{
get
{
return numberChunksValue;
}
set
{
if (value <= 50 && value > 0)
{
numberChunksValue = value;
}
else
{
MessageBox.Show("Number of chunks must be between " +
"0 and 50; defaulting to 10");
numberChunksValue = 10;
}
// Recalculate the progress bar size, if visual styles
// are active.
if (ProgressBarRenderer.IsSupported)
{
SetupProgressBar();
}
}
}
// Draw the progress bar in its normal state.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (ProgressBarRenderer.IsSupported)
{
ProgressBarRenderer.DrawVerticalBar(e.Graphics,
ClientRectangle);
this.Parent.Text = "VerticalProgressBar Enabled";
}
else
{
this.Parent.Text = "VerticalProgressBar Disabled";
}
}
// Initialize the rectangles used to paint the states of the
// progress bar.
private void SetupProgressBar()
{
if (!ProgressBarRenderer.IsSupported)
{
return;
}
// Determine the size of the progress bar frame.
this.Size = new Size(ClientRectangle.Width,
(NumberChunks) * (ProgressBarRenderer.ChunkThickness +
(2 * ProgressBarRenderer.ChunkSpaceThickness)) + 6);
// Initialize the rectangles to draw each step of the
// progress bar.
progressBarRectangles = new Rectangle[NumberChunks];
for (int i = 0; i < NumberChunks; i++)
{
// Use the thickness defined by the current visual style
// to calculate the height of each rectangle. The size
// adjustments ensure that the chunks do not paint over
// the frame.
int filledRectangleHeight =
((i + 1) * (ProgressBarRenderer.ChunkThickness +
(2 * ProgressBarRenderer.ChunkSpaceThickness)));
progressBarRectangles[i] = new Rectangle(
ClientRectangle.X + 3,
ClientRectangle.Y + ClientRectangle.Height - 3
- filledRectangleHeight,
ClientRectangle.Width - 6,
filledRectangleHeight);
}
}
// Handle the timer tick; draw each progressively larger rectangle.
private void progressTimer_Tick(Object myObject, EventArgs e)
{
if (ticks < NumberChunks)
{
using (Graphics g = this.CreateGraphics())
{
ProgressBarRenderer.DrawVerticalChunks(g,
progressBarRectangles[ticks]);
ticks++;
}
}
else
{
progressTimer.Enabled = false;
}
}
// Start the progress bar.
public void Start()
{
if (ProgressBarRenderer.IsSupported)
{
progressTimer.Start();
}
else
{
MessageBox.Show("VerticalScrollBar requires visual styles");
}
}
}
}
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.VisualStyles
Public Class Form1
Inherits Form
Private bar1 As New VerticalProgressBar()
Private button1 As New Button()
Public Sub New()
Me.Size = New Size(500, 500)
bar1.NumberChunks = 30
button1.Location = New Point(150, 10)
button1.Size = New Size(150, 30)
button1.Text = "Start VerticalProgressBar"
AddHandler button1.Click, AddressOf button1_Click
Controls.AddRange(New Control() {button1, bar1})
End Sub
<STAThread()> _
Public Shared Sub Main()
' The call to EnableVisualStyles below does not affect
' whether ProgressBarRenderer.IsSupported is true; as
' long as visual styles are enabled by the operating system,
' IsSupported is true.
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub
' Start the VerticalProgressBar.
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
bar1.Start()
End Sub
End Class
Public Class VerticalProgressBar
Inherits Control
Private numberChunksValue As Integer
Private ticks As Integer
Private progressTimer As New Timer()
Private progressBarRectangles() As Rectangle
Public Sub New()
Me.Location = New Point(10, 10)
Me.Width = 50
' The progress bar will update every second.
progressTimer.Interval = 1000
AddHandler progressTimer.Tick, AddressOf progressTimer_Tick
' This property also calls SetupProgressBar to initialize
' the progress bar rectangles if styles are enabled.
NumberChunks = 20
' Set the default height if visual styles are not enabled.
If Not ProgressBarRenderer.IsSupported Then
Me.Height = 100
End If
End Sub
' Specify the number of progress bar chunks to base the height on.
Public Property NumberChunks() As Integer
Get
Return numberChunksValue
End Get
Set
If value <= 50 AndAlso value > 0 Then
numberChunksValue = value
Else
MessageBox.Show("Number of chunks must be between " + "0 and 50; defaulting to 10")
numberChunksValue = 10
End If
' Recalculate the progress bar size, if visual styles
' are active.
If ProgressBarRenderer.IsSupported Then
SetupProgressBar()
End If
End Set
End Property
' Draw the progress bar in its normal state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If ProgressBarRenderer.IsSupported Then
ProgressBarRenderer.DrawVerticalBar(e.Graphics, ClientRectangle)
Me.Parent.Text = "VerticalProgressBar Enabled"
Else
Me.Parent.Text = "VerticalProgressBar Disabled"
End If
End Sub
' Initialize the rectangles used to paint the states of the
' progress bar.
Private Sub SetupProgressBar()
If Not ProgressBarRenderer.IsSupported Then
Return
End If
' Determine the size of the progress bar frame.
Me.Size = New Size(ClientRectangle.Width, NumberChunks *(ProgressBarRenderer.ChunkThickness + 2 * ProgressBarRenderer.ChunkSpaceThickness) + 6)
' Initialize the rectangles to draw each step of the
' progress bar.
progressBarRectangles = New Rectangle(NumberChunks) {}
Dim i As Integer
For i = 0 To NumberChunks
' Use the thickness defined by the current visual style
' to calculate the height of each rectangle. The size
' adjustments ensure that the chunks do not paint over
' the frame.
Dim filledRectangleHeight As Integer = (i + 1) _
*(ProgressBarRenderer.ChunkThickness + 2 * ProgressBarRenderer.ChunkSpaceThickness)
progressBarRectangles(i) = New Rectangle(ClientRectangle.X + 3, _
ClientRectangle.Y + ClientRectangle.Height - 3 - filledRectangleHeight, _
ClientRectangle.Width - 6, filledRectangleHeight)
Next i
End Sub
' Handle the timer tick; draw each progressively larger rectangle.
Private Sub progressTimer_Tick(ByVal myObject As [Object], ByVal e As EventArgs)
If ticks < NumberChunks Then
Dim g As Graphics = Me.CreateGraphics()
Try
ProgressBarRenderer.DrawVerticalChunks(g, progressBarRectangles(ticks))
ticks += 1
Finally
g.Dispose()
End Try
Else
progressTimer.Enabled = False
End If
End Sub
' Start the progress bar.
Public Sub Start()
If ProgressBarRenderer.IsSupported Then
progressTimer.Start()
Else
MessageBox.Show("VerticalScrollBar requires visual styles")
End If
End Sub
End Class
설명
클래스는 ProgressBarRenderer 운영 체제의 static 현재 비주얼 스타일을 사용하여 진행률 표시줄 컨트롤을 렌더링하는 데 사용할 수 있는 메서드 집합을 제공합니다. 컨트롤 렌더링은 컨트롤의 사용자 인터페이스를 그리는 것을 의미합니다. 이는 현재 비주얼 스타일의 모양이 있어야 하는 사용자 지정 컨트롤을 그리는 경우에 유용합니다. 진행률 표시줄을 그리려면 또는 DrawVerticalBar 메서드를 사용하여 DrawHorizontalBar 빈 막대를 그린 다음 또는 DrawVerticalChunks 메서드를 사용하여 DrawHorizontalChunks 막대에 채우는 요소를 그립니다.
운영 체제에서 비주얼 스타일을 사용하도록 설정하고 애플리케이션 창의 클라이언트 영역에 비주얼 스타일을 적용하는 경우 이 클래스의 메서드는 현재 비주얼 스타일로 진행률 표시줄을 그립니다. 그렇지 않으면 이 클래스의 메서드 및 속성이 throw InvalidOperationException됩니다. 이 클래스의 멤버를 사용할 수 있는지 여부를 확인 하려면 속성의 IsSupported 값을 확인할 수 있습니다.
이 클래스는 , System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.BarVertical및 System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.ChunkSystem.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.ChunkVertical 클래스에 의해 System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.Bar노출되는 요소 중 하나로 설정된 기능을 System.Windows.Forms.VisualStyles.VisualStyleRenderer 래핑합니다. 자세한 내용은 비주얼 스타일을 사용하여 컨트롤 렌더링을 참조하세요.
속성
| Name | Description |
|---|---|
| ChunkSpaceThickness |
진행률 표시줄의 각 내부 부분 사이의 공간 너비를 픽셀 단위로 가져옵니다. |
| ChunkThickness |
진행률 표시줄의 단일 내부 부분의 너비(픽셀)를 가져옵니다. |
| IsSupported |
클래스를 사용하여 비주얼 스타일을 사용하여 진행률 표시줄 컨트롤을 그릴 수 있는지 여부를 ProgressBarRenderer 나타내는 값을 가져옵니다. |
메서드
| Name | Description |
|---|---|
| DrawHorizontalBar(Graphics, Rectangle) |
가로로 채우는 빈 진행률 표시줄 컨트롤을 그립니다. |
| DrawHorizontalChunks(Graphics, Rectangle) |
가로 진행률 표시줄을 채우는 진행률 표시줄 조각 집합을 그립니다. |
| DrawVerticalBar(Graphics, Rectangle) |
세로로 채우는 빈 진행률 표시줄 컨트롤을 그립니다. |
| DrawVerticalChunks(Graphics, Rectangle) |
세로 진행률 표시줄을 채우는 진행률 표시줄 조각 집합을 그립니다. |