Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original
Este tópico ainda não foi avaliado como - Avalie este tópico

Classe ProgressBarRenderer

Fornece métodos usados para processar um BAR de progresso controle com estilos visuais. Esta classe não pode ser herdada.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (em System.Windows.Forms.dll)
public sealed class ProgressBarRenderer

The ProgressBarRenderer classe fornece um conjunto de static métodos que podem ser usados para processar um BAR de progresso controle com o estilo visual corrente do sistema operacional. Processar um controle refere-se a interface de usuário de um controle de desenho. Isso é útil se você está desenhando um controle personalizado deve ter a aparência de estilo visual corrente. Para desenhar um BAR de progresso, use o DrawHorizontalBar ou DrawVerticalBar métodos para desenhar a BAR vazia e, em seguida, use o DrawHorizontalChunks ou DrawVerticalChunks métodos para desenhar os elementos de preenchimento na BAR.

Se estilos visuais estiverem habilitados no sistema operacional e estilos visuais são aplicados à área de cliente janelas de aplicativos, os métodos dessa classe desenhará o BAR de progresso com o estilo visual corrente. Caso contrário, os métodos e propriedades desta classe irão gerar um InvalidOperationException. Para determinar se os membros dessa classe podem ser usados, você pode verificar o valor do IsSupported propriedade.

Essa classe encapsula a funcionalidade de um System.Windows.Forms.VisualStyles.VisualStyleRenderer que é definido como um dos elementos expostos pela System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.Bar, System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.BarVertical, System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.Chunk, e System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar.ChunkVertical classes. Para mais informação, veja Controles de processamento com estilos visuais.

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Observação Zoom, Para Cima e Ampliar:

Só há suporte para estilos visuais nessas plataformas.

O exemplo de código a seguir demonstra como criar um controle personalizado que usa o DrawVerticalBar e DrawVerticalChunks métodos para desenhar uma vertical BAR de progresso. O controle usa um Timer para redesenhar o BAR de progresso com uma informação adicional por segundo. The SetupProgressBar método usa o ChunkThickness e ChunkSpaceThickness propriedades para calcular a altura de cada retângulo progressivamente maior do que é desenhada.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace ProgressBarRendererSample
{
    publicclass 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]
        publicstaticvoid 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.privatevoid button1_Click(object sender, EventArgs e)
        {
            bar1.Start();
        }
    }

    publicclass VerticalProgressBar : Control
    {
        privateint numberChunksValue;
        privateint 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.publicint 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.protectedoverridevoid 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.privatevoid 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.privatevoid 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.publicvoid Start()
        {
            if (ProgressBarRenderer.IsSupported)
            {
                progressTimer.Start();
            }
            else
            {
                MessageBox.Show("VerticalScrollBar requires visual styles");
            }
        }
    }
}


System.Object
  System.Windows.Forms.ProgressBarRenderer
Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.

.NET Framework

Compatível com: 3.5, 3.0, 2.0
Isso foi útil para você?
(1500 caracteres restantes)
Conteúdo da Comunidade Adicionar