/// <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); } }