Exemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = ClientRectangle;
            Graphics  g    = e.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(g, rect);
            rect.Inflate(-3, -3);
            if (Value > 0)
            {
                // As we doing this ourselves we need to draw the chunks on the progress bar
                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }
            // Set the Display text (Either a % amount or our custom text
            string text = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + '%' : CustomText;

            using (Font f = new Font(FontFamily.GenericSerif, 10))
            {
                SizeF len = g.MeasureString(text, f);
                // Calculate the location of the text (the middle of progress bar)
                Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2)));
                // Draw the custom text
                g.DrawString(text, f, Brushes.Red, location);
            }
        }
Exemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect     = ClientRectangle;
            Graphics  graphics = e.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(graphics, rect);
            rect.Inflate(-3, -3);
            // Draw the chunks of the progress bar
            if (Value > 0)
            {
                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(graphics, clip);
            }

            // Set the Display text (Either a % amount or our custom text
            double progress = ((double)Value / (double)Maximum) * 100.0d;
            string text     = Text ?? progress.ToString("0.##") + "%";

            using (Font font = new Font(FontFamily.GenericSerif, 10))
            {
                SizeF len = graphics.MeasureString(text, font);
                // Calculate the location of the text (the middle of progress bar)
                // Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2)));
                Point location = new Point(Convert.ToInt32((Width / 2) - len.Width / 2), Convert.ToInt32((Height / 2) - len.Height / 2));
                // The commented-out code will centre the text into the highlighted area only. This will centre the text regardless of the highlighted area.
                // Draw the custom text
                graphics.DrawString(text, font, Brushes.Black, location);
            }
        }
Exemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = ClientRectangle;

            using (Graphics g = e.Graphics)
            {
                ProgressBarRenderer.DrawHorizontalBar(g, rect);
                rect.Inflate(-3, -3);
                if (Value > 0)
                {
                    // As we doing this ourselves we need to draw the chunks on the progress bar
                    var clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                    ProgressBarRenderer.DrawHorizontalChunks(g, clip);
                }

                // Set the Display text (Either a % amount or our custom text
                var text = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString(CultureInfo.InvariantCulture) + '%' : CustomText;


                SizeF len = g.MeasureString(text, TextFont);
                // Calculate the location of the text (the middle of progress bar)
                // Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2)));
                var location = new Point(Convert.ToInt32((Width / 2) - len.Width / 2), Convert.ToInt32((Height / 2) - len.Height / 2));
                // The commented-out code will centre the text into the highlighted area only. This will centre the text regardless of the highlighted area.
                // Draw the custom text
                g.DrawString(text, TextFont, new SolidBrush(TextColor), location);
            }
        }
Exemplo n.º 4
0
        protected override void OnDrawText(Graphics g, Rectangle bound, StyleListBoxItemStyle style)
        {
            // Decide which color to use for text
            Color textColor;

            if (Selected)
            {
                textColor = style.SelectedTextColor;
            }
            else
            {
                textColor = style.TextColor;
            }

            // Draw text
            TextRenderer.DrawText(g, this.Text, style.Font, bound.Location, textColor);

            // Draw progressbar
            Rectangle progressbarBound = new Rectangle(bound.X, bound.Y + style.Font.Height + 3, 200, 15);

            ProgressBarRenderer.DrawHorizontalBar(g, progressbarBound);

            progressbarBound.Width  = (int)(progressbarBound.Width * ((float)_used / _size));
            progressbarBound.X      = progressbarBound.X + 1;
            progressbarBound.Y      = progressbarBound.Y + 1;
            progressbarBound.Height = progressbarBound.Height - 2;
            ProgressBarRenderer.DrawHorizontalChunks(g, progressbarBound);

            // Draw the below caption
            TextRenderer.DrawText(g, (_size - _used).ToString() + " GB free of " + _size.ToString() + " GB", style.Font, new Point(bound.X, bound.Y + style.Font.Height + 20), textColor);
        }
Exemplo n.º 5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var rect = ClientRectangle;

            rect.Inflate(-3, -3);

            var g = e.Graphics;

            var clip = new Rectangle(rect.X, rect.Y, (int)Math.Round((ValueF / Maximum) * rect.Width), rect.Height);

            if (ProgressBarRenderer.IsSupported)
            {
                ProgressBarRenderer.DrawHorizontalBar(g, rect);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }
            else
            {
                g.FillRegion(Brushes.ForestGreen, new Region(clip));
            }

            var len = g.MeasureString(CustomText, Font);

            // Calculate the location of the text (the middle of progress bar)
            var location = new Point((int)((rect.Width - len.Width) / 2), (int)((rect.Height - len.Height) / 2));

            // Draw the custom text
            g.DrawString(CustomText, Font, SystemBrushes.InfoText, location);
        }
Exemplo n.º 6
0
        private void ProgressText_Paint(object sender, PaintEventArgs e)
        {
            int indent = Level * 8;
            int width  = Width - indent;

            if (ProgressBarRenderer.IsSupported)
            {
                int div = (Total == 0) ? 1 : Total;

                Rectangle bar    = new Rectangle(indent, 0, width, Height);
                Rectangle chunks = new Rectangle(indent, 0, width * Completed / div, Height);

                ProgressBarRenderer.DrawHorizontalBar(e.Graphics, bar);
                ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, chunks);

                e.Graphics.FillRectangle(Overlay, ClientRectangle);
            }

            if (ShowCompletion)
            {
                string text = Completed.ToString() + " / " + Total.ToString() + " hours";
                SizeF  size = e.Graphics.MeasureString(text, TahomaBold);

                e.Graphics.DrawString(text, TahomaBold, BlackBrush,
                                      indent + (width - size.Width) / 2,
                                      (Height - size.Height) / 2);
            }
        }
Exemplo n.º 7
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = ClientRectangle;
            Graphics  g    = e.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(g, rect);
            //rect.Inflate(-3, -3);
            if (Value > 0)
            {
                // As we doing this ourselves we need to draw the chunks on the progress bar
                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }

            // Set the Display text (Either a % amount or our custom text
            string text = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + '%' : CustomText;

            Font f = this.Parent.Font;
            //using (Font f = new Font(this.Parent.Font, FontStyle.Bold))
            //{

            SizeF len = g.MeasureString(text, this.Parent.Font);
            // Calculate the location of the text (the middle of progress bar)
            // Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2)));
            Point location = new Point(Convert.ToInt32((Width / 2) - len.Width / 2), Convert.ToInt32((Height / 2) - len.Height / 2));

            // The commented-out code will centre the text into the highlighted area only. This will centre the text regardless of the highlighted area.
            // Draw the custom text
            g.DrawString(text, f, Brushes.Black, location);
            //}
        }
Exemplo n.º 8
0
        protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
        {
            isVisualStyled = VisualStyleInformation.IsEnabledByUser & VisualStyleInformation.IsSupportedByOS;
            if (value == null)
            {
                return(emptyImage);
            }
            float percentage = (float)((int)value);

            if (percentage == 0)
            {
                return(emptyImage);
            }
            else
            {
                contentGraphics.Clear(Color.Transparent);
                float drawedPercentage = percentage > 100 ? 100 : percentage;
                if (isVisualStyled)
                {
                    bigProgressRect.Width = (int)(66 * drawedPercentage / 100.0f);
                    ProgressBarRenderer.DrawHorizontalBar(contentGraphics, bigBorderRect);
                    ProgressBarRenderer.DrawHorizontalChunks(contentGraphics, bigProgressRect);
                }
                else
                {
                    progressRect.Width = (int)(66 * drawedPercentage / 100.0f);
                    contentGraphics.DrawRectangle(blackPen, borderRect);
                    contentGraphics.FillRectangle(lightGreenBrush, progressRect);
                }
                contentGraphics.DrawString(percentage.ToString("0.00") + "%", this.DataGridView.Font, foreColor, 10, 5);
            }
            return(contentImage);
        }
Exemplo n.º 9
0
    protected override void OnPaint(PaintEventArgs e)
    {
        //背景を描画する
        ProgressBarRenderer.DrawHorizontalBar(e.Graphics, this.ClientRectangle);

        //バーの幅を計算する
        //上下左右1ピクセルの枠の部分を除外して計算する
        double percent = (double)(this.Value - this.Minimum)
                         / (double)(this.Maximum - this.Minimum);
        int       chunksWidth = (int)((double)(this.ClientSize.Width - 2) * percent);
        Rectangle chunksRect  = new Rectangle(1, 1,
                                              chunksWidth, this.ClientSize.Height - 2);

        //バーを描画する
        ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, chunksRect);

        //表示する文字列を決定する
        string displayText = string.Format("{0}%", (int)(percent * 100.0));
        //文字列を描画する
        TextFormatFlags tff = TextFormatFlags.HorizontalCenter |
                              TextFormatFlags.VerticalCenter |
                              TextFormatFlags.SingleLine;

        TextRenderer.DrawText(e.Graphics, displayText, this.Font,
                              this.ClientRectangle, SystemColors.ControlText, tff);
    }
Exemplo n.º 10
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            // base.OnPaint(pe);
            Graphics gr = pe.Graphics;

            gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
            gr.SmoothingMode     = SmoothingMode.HighQuality;
            gr.PixelOffsetMode   = PixelOffsetMode.HighQuality;

            Rectangle RecPB = ClientRectangle;

            ProgressBarRenderer.DrawHorizontalBar(gr, RecPB);
            int       val   = Width * Value / Maximum;
            Rectangle green = new Rectangle(
                1, 1, val - 2, RecPB.Height - 2);

            ProgressBarRenderer.DrawHorizontalChunks(gr, green);
            string text = $"{100.0 * Value / Maximum,6:F2} %";

            float sizefont = Height / 2.5f;
            Font  font     = new Font(FontFamily.GenericMonospace, sizefont, FontStyle.Bold);
            SizeF sizeF    = gr.MeasureString(text, font);

            Point pointT = new Point(
                (int)(Width - sizeF.Width) / 2,
                (int)(Height - sizeF.Height) / 2 + 2
                );

            gr.DrawString(text, font, new SolidBrush(ForeColor), pointT);
        }
Exemplo n.º 11
0
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                Rectangle rect = ClientRectangle;
                Graphics  g    = e.Graphics;

                ProgressBarRenderer.DrawHorizontalBar(g, rect);
                rect.Inflate(-3, -3);
                if (Value > 0)
                {
                    // As we doing this ourselves we need to draw the chunks on the progress bar
                    Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                    ProgressBarRenderer.DrawHorizontalChunks(g, clip);
                }

                string text = string.Format("{0}: {1}/{2}", Label, Value, Maximum);

                using (Font f = new Font(FontFamily.GenericSerif, 10))
                {
                    SizeF len = g.MeasureString(text, f);
                    // Calculate the location of the text (the middle of progress bar)
                    Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2)));
                    // Draw the custom text
                    g.DrawString(text, f, Brushes.Black, location);
                }
            }
            catch { } // temporary workaround (I hope) for execution on other platforms with Mono
        }
Exemplo n.º 12
0
        /// <summary>
        /// Draw our aspect
        /// </summary>
        /// <param name="g"></param>
        /// <param name="r"></param>
        public override void Render(Graphics g, Rectangle r)
        {
            DrawBackground(g, r);

            Rectangle frameRect = Rectangle.Inflate(r, 0 - Padding, 0 - Padding);

            frameRect.Width  = Math.Min(frameRect.Width, MaximumWidth);
            frameRect.Height = Math.Min(frameRect.Height, MaximumHeight);
            frameRect        = AlignRectangle(r, frameRect);

            // Convert our aspect to a numeric value
            // CONSIDER: Is this the best way to do this?
            if (!(Aspect is IConvertible))
            {
                return;
            }
            double aspectValue = ((IConvertible)Aspect).ToDouble(NumberFormatInfo.InvariantInfo);

            Rectangle fillRect = Rectangle.Inflate(frameRect, -1, -1);

            if (aspectValue <= MinimumValue)
            {
                fillRect.Width = 0;
            }
            else if (aspectValue < MaximumValue)
            {
                fillRect.Width = (int)(fillRect.Width * (aspectValue - MinimumValue) / MaximumValue);
            }

            if (UseStandardBar && ProgressBarRenderer.IsSupported)
            {
                ProgressBarRenderer.DrawHorizontalBar(g, frameRect);
                ProgressBarRenderer.DrawHorizontalChunks(g, fillRect);
            }
            else
            {
                g.FillRectangle(BackgroundBrush, frameRect);
                if (fillRect.Width > 0)
                {
                    // FillRectangle fills inside the given rectangle, so expand it a little
                    fillRect.Width++;
                    fillRect.Height++;
                    if (StartColor == Color.Empty)
                    {
                        g.FillRectangle(Brush, fillRect);
                    }
                    else
                    {
                        using (
                            var gradient = new LinearGradientBrush(frameRect, StartColor, EndColor,
                                                                   LinearGradientMode.Horizontal))
                        {
                            g.FillRectangle(gradient, fillRect);
                        }
                    }
                }
                g.DrawRectangle(Pen, frameRect);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Draw me a progress bar.  Copes with visual styles being on or off
        /// </summary>
        /// <param name="g">Graphics to draw to</param>
        /// <param name="r">where to draw the progress bar</param>
        /// <param name="progress">how much progress (0.0-1.0)</param>
        ///
        public static void DrawProgressBar(Graphics g, Rectangle r, double progress)
        {
            if (Application.RenderWithVisualStyles)
            {
                ProgressBarRenderer.DrawHorizontalBar(g, r);

                Rectangle s = new Rectangle(
                    r.X + 4,
                    r.Y + 3,
                    (int)((r.Width - 8) * progress),
                    r.Height - 5);

                ProgressBarRenderer.DrawHorizontalChunks(g, s);
            }
            else
            {
                g.FillRectangle(SystemBrushes.ButtonShadow, r);

                Rectangle s = new Rectangle(
                    r.X + 1,
                    r.Y + 1,
                    r.Width - 1,
                    r.Height - 1);

                g.FillRectangle(SystemBrushes.ButtonHighlight, s);

                Rectangle t = new Rectangle(
                    r.X + 1,
                    r.Y + 1,
                    r.Width - 2,
                    r.Height - 2);

                g.FillRectangle(SystemBrushes.ButtonFace, t);

                int barwidth   = (int)(progress * (r.Width - 4));
                int chunkwidth = 7;
                int chunkgap   = 2;
                int progleft   = 0;
                while (progleft + chunkwidth + chunkgap < barwidth)
                {
                    Rectangle u = new Rectangle(
                        r.X + 2 + progleft,
                        r.Y + 2,
                        chunkwidth,
                        13);

                    g.FillRectangle(SystemBrushes.ActiveCaption, u);
                    progleft += chunkwidth + chunkgap;
                }

                Rectangle v = new Rectangle(
                    r.X + 2 + progleft,
                    r.Y + 2,
                    chunkwidth - progleft,
                    13);

                g.FillRectangle(SystemBrushes.ActiveCaption, v);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Draws a simple progress bar (just the chunks with a grey 1 pixel border). Changes the color to
        /// red if the <see cref="changeColor"/> value is greater than the changeColorProgress value.
        /// </summary>
        /// <param name="g">The device context used for drawing.</param>
        /// <param name="r">The rectangle that specifies where it should be drawn.</param>
        /// <param name="progress">The value of the progress. Should be between 0.0 and 1.0.</param>
        /// <param name="color">The color of the progress bar.</param>
        public static void DrawSimpleProgressBar(Graphics g, Rectangle r, double progress, SimpleProgressBarColor color)
        {
            using (Bitmap bitmap = new Bitmap(r.Width, r.Height))
            {
                using (Graphics gg = Graphics.FromImage(bitmap))
                {
                    //fill background in white
                    gg.FillRectangle(Brushes.White, new Rectangle(0, 0, r.Width, r.Height));
                    Rectangle chunks = new Rectangle(0, 0, (int)(r.Width * progress), r.Height);

                    if (Application.RenderWithVisualStyles)
                    {
                        ProgressBarRenderer.DrawHorizontalChunks(gg, chunks);
                    }
                    else
                    {
                        var brush = Brushes.LightGreen;

                        if (color == SimpleProgressBarColor.Red)
                        {
                            brush = Brushes.Red;
                        }
                        else if (color == SimpleProgressBarColor.Blue)
                        {
                            brush = Brushes.Blue;
                        }

                        gg.FillRectangle(brush, chunks);
                    }
                }

                if (Application.RenderWithVisualStyles && color != SimpleProgressBarColor.Green)
                {
                    for (int i = 0; i < bitmap.Width * progress; i++)
                    {
                        for (int j = 0; j < bitmap.Height; j++)
                        {
                            Color c = bitmap.GetPixel(i, j);

                            if (color == SimpleProgressBarColor.Blue)
                            {
                                bitmap.SetPixel(i, j, Color.FromArgb(c.R, c.B, c.G));
                            }
                            else
                            {
                                //red
                                bitmap.SetPixel(i, j, Color.FromArgb(c.G, c.R, c.B));
                            }
                        }
                    }
                }

                // draw progress bar
                g.DrawImage(bitmap, r);

                // draw rectangle around progress bar.
                g.DrawRectangle(SystemPens.ControlDark, r);
            }
        }
Exemplo n.º 15
0
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                if (UseCustomText == false)
                {
                    return;
                }

                Rectangle rect = ClientRectangle;
                Graphics  g    = e.Graphics;

                ProgressBarRenderer.DrawHorizontalBar(g, rect);
                rect.Inflate(-3, -3);
                if (Value > 0)
                {
                    // As we doing this ourselves we need to draw the chunks on the progress bar
                    Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                    ProgressBarRenderer.DrawHorizontalChunks(g, clip);
                }

                // Set the Display text (Either a % amount or our custom text
                string text = string.Empty;

                int iPercent = Value * 100 / Maximum;

                switch (DisplayStyle)
                {
                case ProgressBarDisplayText.Percentage:
                    text = iPercent.ToString() + '%';
                    break;

                case ProgressBarDisplayText.CustomText:
                    text = CustomText;
                    break;

                case ProgressBarDisplayText.Both:
                    text = string.Format("{0} - {1}%", CustomText, iPercent.ToString());
                    break;
                }


                using (Font f = new Font(FontFamily.GenericSerif, 10))
                {
                    SizeF len = g.MeasureString(text, f);
                    // Calculate the location of the text (the middle of progress bar)
                    Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2)));
                    // Draw the custom text
                    g.DrawString(text, f, Brushes.Black, location);
                }
                //UpdateText();
            }
            catch (Exception exp)
            {
                Logger.WriteErrorLogOnly(exp, "e4af60b8-39dc-49d5-a2f3-931114a6d31f");
            }
        }
Exemplo n.º 16
0
        /// <summary>Paint the progress bar</summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            var gfx  = e.Graphics;
            var rect = ClientRectangle;
            var visual_styles_enabled = ProgressBarRenderer.IsSupported;

            // Draw the background
            if (visual_styles_enabled)
            {
                ProgressBarRenderer.DrawHorizontalBar(gfx, rect);
            }
            else
            {
                gfx.FillRectangle(SystemBrushes.Control, rect);
                gfx.DrawRectangle(SystemPens.ControlDark, rect);
            }

            // Fill with chunks
            if (Value != Minimum)
            {
                const int pad  = 3;
                var       frac = Math_.Frac(Minimum, Value, Maximum);
                var       clip = new Rectangle(rect.X + pad, rect.Y + pad, (int)(frac * (rect.Width - 2 * pad)), rect.Height - 2 * pad);
                if (visual_styles_enabled)
                {
                    ProgressBarRenderer.DrawHorizontalChunks(gfx, clip);
                }
                else
                {
                    gfx.FillRectangle(SystemBrushes.Highlight, clip);
                }
            }

            // Draw the text
            using (var b = new SolidBrush(ForeColor))
            {
                if (TextL.Text.HasValue())
                {
                    var sz = gfx.MeasureString(TextL.Text, TextL.Font);
                    gfx.DrawString(TextL.Text, TextL.Font, b, new PointF(rect.Left + (RightToLeftLayout ? rect.Width - sz.Width : 0), rect.Top + (rect.Height - sz.Height) / 2f));
                }
                if (TextC.Text.HasValue())
                {
                    var sz = gfx.MeasureString(TextC.Text, TextC.Font);
                    gfx.DrawString(TextC.Text, TextC.Font, b, new PointF(rect.Left + (rect.Width - sz.Width) / 2, rect.Top + (rect.Height - sz.Height) / 2f));
                }
                if (TextR.Text.HasValue())
                {
                    var sz = gfx.MeasureString(TextR.Text, TextR.Font);
                    gfx.DrawString(TextR.Text, TextR.Font, b, new PointF(rect.Left + (RightToLeftLayout ? 0 : rect.Width - sz.Width), rect.Top + (rect.Height - sz.Height) / 2f));
                }
            }
        }
Exemplo n.º 17
0
        public override void Render(Graphics g, Rectangle r)
        {
            this.DrawBackground(g, r);
            Rectangle inner = Rectangle.Inflate(r, -this.Padding, -this.Padding);

            inner.Width  = Math.Min(inner.Width, this.MaximumWidth);
            inner.Height = Math.Min(inner.Height, this.MaximumHeight);
            inner        = this.AlignRectangle(r, inner);
            IConvertible aspect = base.Aspect as IConvertible;

            if (aspect != null)
            {
                double    num    = aspect.ToDouble(NumberFormatInfo.InvariantInfo);
                Rectangle bounds = Rectangle.Inflate(inner, -1, -1);
                if (num <= this.MinimumValue)
                {
                    bounds.Width = 0;
                }
                else if (num < this.MaximumValue)
                {
                    bounds.Width = (int)((bounds.Width * (num - this.MinimumValue)) / this.MaximumValue);
                }
                if (!((!this.UseStandardBar || !ProgressBarRenderer.IsSupported) || base.IsPrinting))
                {
                    ProgressBarRenderer.DrawHorizontalBar(g, inner);
                    ProgressBarRenderer.DrawHorizontalChunks(g, bounds);
                }
                else
                {
                    g.FillRectangle(this.BackgroundBrush, inner);
                    if (bounds.Width > 0)
                    {
                        bounds.Width++;
                        bounds.Height++;
                        if (this.GradientStartColor == Color.Empty)
                        {
                            g.FillRectangle(this.Brush, bounds);
                        }
                        else
                        {
                            using (LinearGradientBrush brush = new LinearGradientBrush(inner, this.GradientStartColor, this.GradientEndColor, LinearGradientMode.Horizontal))
                            {
                                g.FillRectangle(brush, bounds);
                            }
                        }
                    }
                    g.DrawRectangle(this.Pen, inner);
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            ProgressBarRenderer.DrawHorizontalBar(e.Graphics, this.ClientRectangle);
            Rectangle bounds = new Rectangle
            {
                X      = this.ClientRectangle.X,
                Y      = this.ClientRectangle.Y,
                Width  = (Int32)Math.Floor(((double)this.Value / this.Maximum) * this.ClientRectangle.Width),
                Height = this.ClientRectangle.Height
            };

            bounds.Inflate(-1, -1);
            ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, bounds);
        }
Exemplo n.º 19
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var rect = ClientRectangle;
            var g    = e.Graphics;

            // Validate that the user has enabled visual styles in the operating system
            if (ProgressBarRenderer.IsSupported)
            {
                ProgressBarRenderer.DrawHorizontalBar(g, rect);
                rect.Inflate(-3, -3);
                if (Value > 0)
                {
                    // As we doing this ourselves we need to draw the chunks on the progress bar
                    var clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width),
                                             rect.Height);
                    ProgressBarRenderer.DrawHorizontalChunks(g, clip);
                }
            }

            // Set the Display text (Either a % amount or our custom text
            string text = "";

            switch (DisplayStyle)
            {
            case ProgressBarDisplayText.Both:
                text = String.Format("{0}: {1}%", CustomText, Value);
                break;

            case ProgressBarDisplayText.CustomText:
                text = CustomText;
                break;

            case ProgressBarDisplayText.Percentage:
                text = String.Format("{0}%", Value);
                break;
            }

            using (var f = new Font(FontFamily.GenericSansSerif, 8.25F))
            {
                var len = g.MeasureString(text, f);
                // Calculate the location of the text (the middle of progress bar)
                // Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2)));
                var location = new Point(Convert.ToInt32((Width / 2) - len.Width / 2),
                                         Convert.ToInt32((Height / 2) - len.Height / 2));
                // The commented-out code will centre the text into the highlighted area only. This will centre the text regardless of the highlighted area.
                // Draw the custom text
                g.DrawString(text, f, Brushes.Black, location);
            }
        }
Exemplo n.º 20
0
        //public new List<BetterListViewExColumnHeader> Columns = new List<BetterListViewExColumnHeader>();

        protected override void OnDrawItem(BetterListViewDrawItemEventArgs eventArgs)
        {
            int percentOutOf = 100;

            base.OnDrawItem(eventArgs);
            if (View != BetterListViewView.Details)
            {
                return;
            }
            Graphics graphics = eventArgs.Graphics;

            foreach (BetterListViewSubItem current in eventArgs.Item.SubItems)
            {
                if (current.Index >= base.Columns.Count)
                {
                    break;
                }
                Rectangle boundsInner = eventArgs.ItemBounds.SubItemBounds[current.Index].BoundsInner;
                if ((boundsInner.Width > 0) && (boundsInner.Height > 0))
                {
                    BetterListViewExColumnHeader blvExColumnHeader = (BetterListViewExColumnHeader)Columns[current.Index];
                    switch (blvExColumnHeader?.ColumnType)
                    {
                    case BetterListViewExColumnType.PercentDone:
                        if ((boundsInner.Width > 4) && (boundsInner.Height > 4) && current.Value is short)
                        {
                            int       num3      = Math.Min(16, boundsInner.Height);
                            Rectangle rectangle = new Rectangle(boundsInner.Left, boundsInner.Top + ((boundsInner.Height - num3) >> 1), boundsInner.Width - 2, num3);
                            short     num4      = (short)current.Value;
                            if (ProgressBarRenderer.IsSupported)
                            {
                                Rectangle bounds = new Rectangle(rectangle.Left + 1, rectangle.Top + 1, (int)num4 * (rectangle.Width - 1) / percentOutOf, rectangle.Height - 2);
                                ProgressBarRenderer.DrawHorizontalBar(graphics, rectangle);
                                ProgressBarRenderer.DrawHorizontalChunks(graphics, bounds);
                            }
                            else
                            {
                                Rectangle rect3 = new Rectangle(rectangle.Left + 1, rectangle.Top + 1, (int)num4 * (rectangle.Width - 1) / percentOutOf, rectangle.Height - 1);
                                graphics.FillRectangle(SystemBrushes.Window, rectangle);
                                graphics.FillRectangle(SystemBrushes.Highlight, rect3);
                                graphics.DrawRectangle(SystemPens.Control, rectangle);
                            }
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 21
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            Rectangle rect = ClientRectangle;

            ProgressBarRenderer.DrawHorizontalBar(g, rect);
            rect.Inflate(-3, -3);
            if (Value > 0)
            {
                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }

            g.DrawString(Text, Font, textBrush, ClientRectangle, textFormat);
        }
Exemplo n.º 22
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rc = new Rectangle(10, 10, 100, 20);

            ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rc);
            rc = new Rectangle(10, 10, 50, 20);
            ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, rc);
            xpos += 3;
            if (xpos >= 30)
            {
                xpos = -150;            // Note: intentionally too far left
            }
            rc = new Rectangle(xpos, 10, 50, 20);
            pulseRenderer.DrawBackground(e.Graphics, rc);
            moveRenderer.DrawBackground(e.Graphics, rc);
        }
Exemplo n.º 23
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = ClientRectangle;
            Graphics  g    = e.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(g, rect);
            if (Value > 0)
            {
                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }
            if (Text != "")
            {
                g.DrawString(Text, TextFont, new SolidBrush(TextColor), getLocation(g));
            }
        }
Exemplo n.º 24
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle bounds = this.ClientRectangle;

            ProgressBarRenderer.DrawHorizontalBar(e.Graphics, bounds);

            if (this.Value > 0)
            {
                Rectangle clip = new Rectangle((int)bounds.X + 1, (int)bounds.Y + 1, (int)(((float)this.Value / (float)this.Maximum) * (float)bounds.Width - 2), (int)bounds.Height - 2);
                ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, clip);

                if (bDrawText)
                {
                    e.Graphics.DrawString(this.Value.ToString("F00") + "%", new Font("Lucida Console", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(Width / 2 - 13, Height / 2 - 6));
                }
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Steps the bar.
 /// </summary>
 internal void Step()
 {
     if (++_val != Stop)
     {
         using (var graphics = CreateGraphics())
         {
             var rect = new Rectangle(ClientRectangle.X,
                                      ClientRectangle.Y,
                                      ClientRectangle.Width * _val / Stop,
                                      ClientRectangle.Height);
             ProgressBarRenderer.DrawHorizontalChunks(graphics, rect);
         }
     }
     else
     {
         Close();
     }
 }
        protected override void OnPaint(PaintEventArgs pe)
        {
            Rectangle rect = this.ClientRectangle;
            Graphics  g    = pe.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(g, rect);
            if (this.Value > 0)
            {
                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)this.Value / this.Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }
            using (Font f = new Font("Verdana", 22, FontStyle.Regular))
            {
                SizeF size     = g.MeasureString(string.Format("{0} %", this.Value), f);
                Point location = new Point((int)((rect.Width / 2) - (size.Width / 2)), (int)((rect.Height / 2) - (size.Height / 2) + 2));
                g.DrawString(string.Format("{0} %", this.Value), f, Brushes.MidnightBlue, location);
            }
        }
Exemplo n.º 27
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = ClientRectangle;

            ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rect);
            rect.Inflate(-3, -3);
            if (Value > 0)
            {
                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, clip);
            }
            if (ShowText)
            {
                string text     = String.Format(Text, CurrentTrack, TotalTracks);
                float  center_x = this.Width / 2.0f - (e.Graphics.MeasureString(text, SystemFonts.DefaultFont).Width / 2.0f);
                float  center_y = this.Height / 2.0f - (e.Graphics.MeasureString(text, SystemFonts.DefaultFont).Height / 2.0f);
                e.Graphics.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, new PointF(center_x, center_y));
            }
        }
Exemplo n.º 28
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            Rectangle rect = this.ClientRectangle;
            Graphics  g    = pe.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(g, rect);
            if (this.Value > 0)
            {
                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)this.Value / this.Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }
            using (Font f = new Font(FontFamily.GenericMonospace, 10))
            {
                SizeF size     = g.MeasureString(string.Format("{0} %", this.Value), f);
                Point location = new Point((int)((rect.Width / 2) - (size.Width / 2)), (int)((rect.Height / 2) - (rect.Height / 2) + 2));
                g.DrawString(string.Format("{0} %", this.Value), f, Brushes.Black, location);
            }
            //base.OnPaint(pe);
        }
Exemplo n.º 29
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle clientRectangle = base.ClientRectangle;
            Graphics  graphics        = e.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(graphics, clientRectangle);
            clientRectangle.Inflate(-3, -3);
            if (base.Value > 0)
            {
                Rectangle bounds = new Rectangle(clientRectangle.X, clientRectangle.Y, (int)Math.Round((float)base.Value / (float)base.Maximum * (float)clientRectangle.Width), clientRectangle.Height);
                ProgressBarRenderer.DrawHorizontalChunks(graphics, bounds);
            }
            string text = (DisplayStyle == ProgressBarDisplayText.Percentage) ? (base.Value + "%") : CustomText;

            using (Font font = new Font(FontFamily.GenericSerif, 10f))
            {
                SizeF sizeF = graphics.MeasureString(text, font);
                graphics.DrawString(point: new Point(Convert.ToInt32((float)(base.Width / 2) - sizeF.Width / 2f), Convert.ToInt32((float)(base.Height / 2) - sizeF.Height / 2f)), s: text, font: font, brush: Brushes.Black);
            }
        }
Exemplo n.º 30
0
            protected override void OnPaint(PaintEventArgs e)
            {
                // let the system do base work first
                base.OnPaint(e);
                // grab some tools
                var rect = ClientRectangle;
                var g    = e.Graphics;

                // draw the background
                ProgressBarRenderer.DrawHorizontalBar(g, rect);
                rect.Inflate(-3, -3);
                // then chunk
                if (Value > 0)
                {
                    Rectangle clip = new Rectangle(rect.X, rect.Y, Value * rect.Width / Maximum, rect.Height);
                    ProgressBarRenderer.DrawHorizontalChunks(g, clip);
                }
                // append text
                g.DrawString(CustomText, SystemFonts.DefaultFont, SystemBrushes.ControlText,
                             this.DisplayRectangle, Format);
            }