ProgressBarRendererとは? わかりやすく解説

ProgressBarRenderer クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

visual スタイル使用してプログレス バー コントロール描画するメソッド用意します。このクラス継承できません。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public NotInheritable Class
 ProgressBarRenderer
Dim instance As ProgressBarRenderer
public sealed class ProgressBarRenderer
public ref class ProgressBarRenderer sealed
public final class ProgressBarRenderer
public final class ProgressBarRenderer
解説解説

ProgressBarRenderer クラスには、オペレーティング システム現在の visual スタイル使用してプログレス バー コントロール描画するために使用できる一連の static メソッド用意されています。コントロール描画とは、コントロールユーザー インターフェイス描画することです。これは、現在の visual スタイル外観を持つカスタム コントロール描画する場合役立ちますプログレス バー描画するには、DrawHorizontalBar メソッドまたは DrawVerticalBar メソッド使用して空のバー描画してから、DrawHorizontalChunks メソッドまたは DrawVerticalChunks メソッド使用してバー表示する要素描画ます。

オペレーティング システムvisual スタイル有効にされており、visual スタイルアプリケーション ウィンドウクライアント領域適用されている場合、このクラスメソッド現在の visual スタイル使用してプログレス バー描画ます。それ以外場合は、このクラスメソッドプロパティは InvalidOperationException をスローます。このクラスメンバ使用できるかどうか確認するには、IsSupported プロパティの値をチェックします

このクラスは、System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.Bar、System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.BarVertical、System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.Chunk、および System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.ChunkVertical の各クラス公開する要素うちいずれかに設定されている System.Windows.Forms.VisualStyles.VisualStyleRenderer の機能ラップます。詳細については、「visual スタイル使用されているコントロールレンダリング」を参照してください

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 プラットフォームメモ : visual スタイルは、これらのプラットフォームでのみサポートされます。

使用例使用例

DrawVerticalBar メソッドDrawVerticalChunks メソッド使用して垂直プログレス バー描画するカスタム コントロール作成する方法を、次のコード例示します。このコントロールは、Timer使用して要素追加されプログレス バーを 1 秒ごとに再描画ます。SetupProgressBar メソッドは、ChunkThickness プロパティと ChunkSpaceThickness プロパティ使用して描画対象徐々に大きくなる四角形の高さを、そのつど計算します

Imports System
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 'New
    
    
    <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 'Main
    
    
    ' Start the VerticalProgressBar.
    Private Sub button1_Click(ByVal
 sender As Object, ByVal
 e As EventArgs) 
        bar1.Start()
    
    End Sub 'button1_Click
End Class 'Form1


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 'New
    
    ' 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 'OnPaint
    
    ' 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 'SetupProgressBar
    
    ' 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 'progressTimer_Tick
    
    ' Start the progress bar.
    Public Sub Start() 
        If ProgressBarRenderer.IsSupported Then
            progressTimer.Start()
        Else
            MessageBox.Show("VerticalScrollBar requires visual
 styles")
        End If
    
    End Sub 'Start
End Class 'VerticalProgressBar
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");
            }
        }
    }
}
#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());
}

継承階層継承階層
System.Object
  System.Windows.Forms.ProgressBarRenderer
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ProgressBarRenderer メンバ
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

ProgressBarRenderer プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

ProgressBarRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

ProgressBarRenderer メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ProgressBarRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

ProgressBarRenderer メンバ

visual スタイル使用してプログレス バー コントロール描画するメソッド用意します。このクラス継承できません。

ProgressBarRenderer データ型公開されるメンバを以下の表に示します


パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ProgressBarRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement


このページでは「.NET Framework クラス ライブラリ リファレンス」からProgressBarRendererを検索した結果を表示しています。
Weblioに収録されているすべての辞書からProgressBarRendererを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からProgressBarRenderer を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ProgressBarRenderer」の関連用語

ProgressBarRendererのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ProgressBarRendererのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS