protected override void OnPaint(PaintEventArgs e) { var rect = ClientRectangle; var g = e.Graphics; ProgressBarRenderer.DrawHorizontalBar(g, rect); rect.Inflate(-1, -1); if (Value > 0) { var width = FillStyle == VolumeMeterFillStyle.Horiztonal ? (int)Math.Round((float)Value / Maximum * rect.Width) : rect.Width; var height = FillStyle == VolumeMeterFillStyle.Vertical ? (int)Math.Round((float)Value / Maximum * rect.Height) : rect.Height; var xPos = rect.X; var yPos = FillStyle == VolumeMeterFillStyle.Vertical ? rect.Y + (rect.Height - height) : rect.Y; var barRect = new Rectangle(xPos, yPos, width, height); var colors = new ColorBlend(); colors.Positions = volumeMeterGradientPositions; colors.Colors = volumeMeterGradientColors; var gradentBrush = new LinearGradientBrush( rect, Color.Black, Color.Black, FillStyle == VolumeMeterFillStyle.Vertical ? 270f : 0f ); gradentBrush.InterpolationColors = colors; e.Graphics.FillRectangle(gradentBrush, barRect); } }
// private LinearGradientMode GradMode = LinearGradientMode.ForwardDiagonal; protected override void OnPaint(PaintEventArgs e) { LinearGradientBrush brush = null; Rectangle rec = new Rectangle(0, 0, this.Width, this.Height); if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rec); } rec.Width = (int)(rec.Width * ((double)base.Value / Maximum)) - 4; rec.Height -= 4; if (rec.Width == 0) { rec.Width = -4; } if (rec.Height == 0) { rec.Height = -4; } brush = new LinearGradientBrush(rec, System.Drawing.ColorTranslator.FromHtml("#19abaa"), System.Drawing.ColorTranslator.FromHtml("#19abaa"), LinearGradientMode.ForwardDiagonal); //brush = new LinearGradientBrush(rec, this.ForeColor, this.BackColor, LinearGradientMode.ForwardDiagonal); e.Graphics.FillRectangle(brush, 2, 2, rec.Width, rec.Height); }
protected override void OnPaint(PaintEventArgs e) { Rectangle rec = e.ClipRectangle; double rate = (double)Value / Maximum; rec.Width = (int)(rec.Width * rate) - 4; if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle); } rec.Height = rec.Height - 4; if (rate >= 0.75) { e.Graphics.FillRectangle(Brushes.Lime, 2, 2, rec.Width, rec.Height); } else if (rate >= 0.5) { e.Graphics.FillRectangle(Brushes.Yellow, 2, 2, rec.Width, rec.Height); } else if (rate >= 0.25) { e.Graphics.FillRectangle(Brushes.Orange, 2, 2, rec.Width, rec.Height); } else { e.Graphics.FillRectangle(Brushes.Red, 2, 2, rec.Width, rec.Height); } }
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); }
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; string text = (CustomText == null) ? "Starting!" : CustomText; SizeF len = g.MeasureString(text, this.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, this.font, this.color, location); }
protected override void OnPaint(PaintEventArgs e) { // create action Action thing = new Action(() => { Rectangle rec = e.ClipRectangle; rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4; if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle); } rec.Height = rec.Height - 4; e.Graphics.FillRectangle(Brushes.MediumPurple, 2, 2, rec.Width, rec.Height); }); // invoke on control if invoke is required if (InvokeRequired) { Invoke(thing); } else { thing.Invoke(); // otherwise just invoke it directly on the same thread } }
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 - 2, rect.Y - 2, (int)Math.Round(((float)Value / Maximum) * rect.Width) + 4, rect.Height + 4); g.FillRectangle(new SolidBrush(this.BackColor), 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, FontStyle.Bold)) { 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)) + 4); // Draw the custom text g.DrawString(text, f, new SolidBrush(this.ForeColor), location); } }
protected override void OnPaint(PaintEventArgs e) { using (Image offscreenImage = new Bitmap(Width, Height)) { using (Graphics offscreen = Graphics.FromImage(offscreenImage)) { Rectangle rect = new Rectangle(0, 0, Width, Height); if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(offscreen, rect); } rect.Width = (int)(rect.Width * ((double)Value / Maximum)); if (rect.Width == 0) { using (Pen pen = new Pen(Color.Black)) { offscreen.DrawRectangle(pen, 0, 0, rect.Width, rect.Height); } } else { using (LinearGradientBrush brush = new LinearGradientBrush(rect, BackColor, ForeColor, LinearGradientMode.Vertical)) { offscreen.FillRectangle(brush, 0, 0, rect.Width, rect.Height); } } e.Graphics.DrawImage(offscreenImage, 0, 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); } }
protected override void OnPaint(PaintEventArgs e) { Rectangle rect = ClientRectangle; Graphics g = e.Graphics; ProgressBarRenderer.DrawHorizontalBar(g, rect); // Border. rect.Inflate(-1, -1); // Bar. if (Value > 0) { Brush brush = new SolidBrush(ForeColor); g.FillRectangle(brush, rect.X, rect.Y, (int)Math.Round((float)Value / Maximum * rect.Width), rect.Height); } string text = Value.ToString() + '/' + Maximum; // Text. using (Font f = new Font(FontFamily.GenericMonospace, 10)) { SizeF strLen = g.MeasureString(text, f); Point location = new Point((int)((rect.Width / 2) - (strLen.Width / 2)), (int)((rect.Height / 2) - (strLen.Height / 2))); g.DrawString(text, f, Brushes.Black, location); } }
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); }
protected override void OnPaint(PaintEventArgs e) { if (!Application.RenderWithVisualStyles) { base.OnPaint(e); 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 = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + '%' : CustomText; using (Font f = new Font("Tahoma", 8.25f)) { 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); } }
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); } }
protected override void OnPaint(PaintEventArgs e) { Rectangle rec = e.ClipRectangle; rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4; if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle); } rec.Height = rec.Height - 4; if (Program.mainWindow == null) { return; } e.Graphics.FillRectangle(new SolidBrush(Program.mainWindow.volBarBackColor), 0, 0, Width, Height); e.Graphics.FillRectangle(new SolidBrush(Program.mainWindow.volBarForeColor), 2, 2, rec.Width, rec.Height); if (HasBorder) { e.Graphics.DrawRectangle(new Pen(Program.mainWindow.volBarForeColor, BorderThickness), 0, 0, Width - BorderThickness, Height - BorderThickness); } string toWrite = (int)(((float)Value / (float)Maximum) * 100) + "%"; if (rec.Height < 6) { return; } Font ft = new Font(Program.mainWindow.font2.FontFamily, rec.Height - 2, Program.mainWindow.font2.Style); SizeF sz = e.Graphics.MeasureString(toWrite, ft); e.Graphics.DrawString(toWrite, ft, Brushes.Black, new PointF((Width - sz.Width) / 2, (Height - sz.Height) / 2 + (int)(sz.Height * 0.15))); }
protected override void OnPaint(PaintEventArgs e) { var rect = ClientRectangle; var g = e.Graphics; ProgressBarRenderer.DrawHorizontalBar(g, rect); rect.Inflate(-1, -1); if (Value > 0) { var barRect = new Rectangle( rect.X, rect.Y, (int)Math.Round((float)Value / Maximum * rect.Width), rect.Height ); var barColor = Value >= Threshold ? TriggeredColor : NormalColor; var barBrush = new SolidBrush(barColor); e.Graphics.FillRectangle(barBrush, barRect); var thresholdIndicatorRect = new Rectangle( rect.X + (int)Math.Round((float)Threshold / Maximum * rect.Width), rect.Y, 1, rect.Height ); var thresholdIndicatorColor = Value >= Threshold ? TriggeredIndicatorColor : NormalIndicatorColor; var thresholdIndicatorBrush = new SolidBrush(thresholdIndicatorColor); e.Graphics.FillRectangle(thresholdIndicatorBrush, thresholdIndicatorRect); } }
protected override void OnPaint(PaintEventArgs e) { const int inset = 2; // A single inset value to control the sizing of the inner rect. using (Image offscreenImage = new Bitmap(Width, Height)) { using (var offscreen = Graphics.FromImage(offscreenImage)) { var rect = new Rectangle(0, 0, Width, Height); if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(offscreen, rect); } rect.Inflate(new Size(-inset, -inset)); // Deflate inner rect. rect.Width = (int)(rect.Width * ((double)Value / Maximum)); if (rect.Width == 0) { rect.Width = 1; // Can't draw rec with width of 0. } var brush = new SolidBrush(Color.Green); offscreen.FillRectangle(brush, inset, inset, rect.Width, rect.Height); e.Graphics.DrawImage(offscreenImage, 0, 0); offscreenImage.Dispose(); } } }
protected override void OnPaint(PaintEventArgs e) { SolidBrush brush = null; Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rect); } Pen pen = new Pen(this.BackColor, 1); //绘制边框 e.Graphics.DrawRectangle(pen, rect); //绘制背景 e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 2, 2, rect.Width - 4, rect.Height - 4); rect.Height -= 4; rect.Width = (int)(rect.Width * ((double)Value / Maximum)) - 4; brush = new SolidBrush(this.ForeColor); //绘制当前进度 //myColor = this.ForeColor; //e.Graphics.FillRectangle(new SolidBrush(myColor), x, y, rect.Width - 1, rect.Height); e.Graphics.FillRectangle(brush, x, y, rect.Width - 1, rect.Height); string text = string.Format("{0}% Complete...", Value * 100 / Maximum); using (var font = new Font(FontFamily.GenericSansSerif, 10)) { Graphics g = e.Graphics; SizeF sz = g.MeasureString(text, font); var location = new PointF(this.Width / 2 - 15, 1); g.DrawString(text, font, Brushes.SteelBlue, location); } }
protected override void OnPaint(PaintEventArgs e) { System.Drawing.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 System.Drawing.Rectangle clip = new System.Drawing.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 = Value + " / " + Maximum;//DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + '%' : CustomText; using (System.Drawing.Font f = new System.Drawing.Font(FontFamily.GenericSerif, 9, FontStyle.Bold)) { 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))); System.Drawing.Point location = new System.Drawing.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); } }
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); }
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); }
protected override void OnPaint(PaintEventArgs e) { Rectangle rec = e.ClipRectangle; rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4; if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle); } rec.Height = rec.Height - 4; e.Graphics.FillRectangle(Brushes.MediumTurquoise, 2, 2, rec.Width, rec.Height); // Set the Display text (Either a % amount or our custom text string text = CustomText; using (Font f = new Font(FontFamily.GenericSerif, 10)) { SizeF len = e.Graphics.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))); 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 e.Graphics.DrawString(text, f, Brushes.Red, location); } }
protected override void OnPaint(PaintEventArgs e) { if (IsWinXP) { base.OnPaint(e); return; } using (Image offscreenImage = new Bitmap(Width, Height)) { using (Graphics offscreen = Graphics.FromImage(offscreenImage)) { Rectangle rect = new Rectangle(0, 0, Width, Height); if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(offscreen, rect); } rect.Inflate(new Size(-inset, -inset)); // Deflate inner rect. rect.Width = (int)(rect.Width * ((double)Value / Maximum)); if (rect.Width == 0) { rect.Width = 1; // Can't draw rec with width of 0. } LinearGradientBrush brush = new LinearGradientBrush(rect, Colors[0], Colors[1], GradientMode); offscreen.FillRectangle(brush, inset, inset, rect.Width, rect.Height); e.Graphics.DrawImage(offscreenImage, 0, 0); offscreenImage.Dispose(); } } }
private void DrawComputerTiledModeView(IListItemEx sho, Graphics g, RectangleF lblrectTiles, StringFormat fmt) { var driveInfo = new DriveInfo(sho.ParsingName); if (driveInfo.IsReady) { ProgressBarRenderer.DrawHorizontalBar(g, new Rectangle((Int32)lblrectTiles.Left, (Int32)lblrectTiles.Bottom + 4, (Int32)lblrectTiles.Width - 10, 10)); var fullProcent = (100 * (driveInfo.TotalSize - driveInfo.AvailableFreeSpace)) / driveInfo.TotalSize; var barWidth = (lblrectTiles.Width - 12) * fullProcent / 100; var rec = new Rectangle((Int32)lblrectTiles.Left + 1, (Int32)lblrectTiles.Bottom + 5, (Int32)barWidth, 8); var gradRec = new Rectangle(rec.Left, rec.Top - 1, rec.Width, rec.Height + 2); var criticalUsed = fullProcent >= 90; var warningUsed = fullProcent >= 75; var averageUsed = fullProcent >= 50; var brush = new LinearGradientBrush(gradRec, criticalUsed ? Color.FromArgb(255, 0, 0) : warningUsed ? Color.FromArgb(255, 224, 0) : averageUsed ? Color.FromArgb(0, 220, 255) : Color.FromArgb(199, 248, 165), criticalUsed ? Color.FromArgb(150, 0, 0) : warningUsed ? Color.FromArgb(255, 188, 0) : averageUsed ? Color.FromArgb(43, 84, 235) : Color.FromArgb(101, 247, 0), LinearGradientMode.Vertical); g.FillRectangle(brush, rec); brush.Dispose(); var lblrectSubiTem3 = new RectangleF(lblrectTiles.Left, lblrectTiles.Bottom + 16, lblrectTiles.Width, 15); Font subItemFont = SystemFonts.IconTitleFont; var subItemTextBrush = new SolidBrush(SystemColors.ControlDarkDark); g.DrawString($"{ShlWapi.StrFormatByteSize(driveInfo.AvailableFreeSpace)} free of {ShlWapi.StrFormatByteSize(driveInfo.TotalSize)}", subItemFont, subItemTextBrush, lblrectSubiTem3, fmt); subItemFont.Dispose(); subItemTextBrush.Dispose(); } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { Rectangle rec = e.ClipRectangle; rec.Width = Convert.ToInt32(Math.Truncate(rec.Width * (Convert.ToDouble(this.Value) / Maximum))); if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle); } Color baseColor = this.Enabled ? this._BaseColor : this._DisableBaseColor; Color borderColor = this.Enabled ? this._BorderColor : this._DisableBorderColor; Color innerBorderColor = this.Enabled ? this._InnerBorderColor : this._DisableInnerBorderColor; try { this.RenderGlassBackground( e.Graphics, rec, baseColor, borderColor, innerBorderColor, RoundStyle.None, 0, 0.0f, true, true, LinearGradientMode.Horizontal); } catch { } }
protected override void OnPaint(PaintEventArgs e) { Rectangle rect = ClientRectangle; Graphics g = e.Graphics; string text = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + '%' : CustomText; int numFromText = Convert.ToInt32(CustomText); ProgressBarRenderer.DrawHorizontalBar(g, rect); rect.Inflate(-3, -3); if (numFromText > 0) { var temp = Brushes.Green; if (numFromText >= 70 && numFromText < 90) { temp = Brushes.Orange; } else if (numFromText >= 90) { temp = Brushes.Red; } // 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.DrawHorizontalBar(g, clip); e.Graphics.FillRectangle(temp, clip); } SizeF len = g.MeasureString(text, new Font(FontFamily.GenericSansSerif, 10)); customText.Location = new Point(Convert.ToInt32((Width / 2) - len.Width / 2), Convert.ToInt32((Height / 2) - len.Height / 2)); customText.Text = text + "%"; }
protected override void OnPaint(PaintEventArgs e) { Rectangle rec = e.ClipRectangle; rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4; if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle); } Rectangle rect = new Rectangle(new Point(0, 0), new Size(Maximum, rec.Height)); e.Graphics.FillRectangle(Brushes.Gray, 0, 0, Width, rect.Height); e.Graphics.FillRectangle(_brush, 0, 0, rec.Width, rec.Height); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; String estimatedTime = SecondsRemaining > 0 ? $"- Time left: {Utilities.TimeFormatUtil.GetCountdownFormat(SecondsRemaining,false)}" : ""; if (ExtraText != null) { estimatedTime += ExtraText; } e.Graphics.DrawString($"{this.Value}% {estimatedTime}", this.font, Brushes.White, this.Width / 2, this.Height / 2, sf); }
protected override void OnPaint(PaintEventArgs e) { Rectangle rec = e.ClipRectangle; rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4; if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle); } rec.Height = rec.Height - 4; e.Graphics.FillRectangle(Brushes.DodgerBlue, 2, 2, rec.Width, rec.Height); string text = (DisplayStyle == ProgressBarDisplayText.Value) ? $"{Value.ToString()}/{Maximum.ToString()}" : CustomText; using (Font f = new Font(FontFamily.GenericSansSerif, 8)) { SizeF len = e.Graphics.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))); 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 e.Graphics.DrawString(text, f, Brushes.Black, location); } }
private void tv_sheets_DrawNode(object sender, DrawTreeNodeEventArgs e) { e.DrawDefault = true; var sheet = SheetForNode(e.Node); if (sheet == null) { return; } float progress = ProgressForSheet(sheet); int width = tv_sheets.Width - e.Bounds.Right; if (width > 200) { width = 200; } // Figure out bounds var boundsForProgress = new Rectangle(tv_sheets.Width - width - 5, e.Bounds.Top, width - 10, e.Bounds.Height); boundsForProgress.Inflate(0, -3); // Draw background ProgressBarRenderer.DrawHorizontalBar(e.Graphics, boundsForProgress); // Draw foreground var fillForProgress = boundsForProgress; fillForProgress.Width = (int)(progress * fillForProgress.Width); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(6, 176, 37)), fillForProgress); }
protected override void OnPaint(PaintEventArgs e) { const int inset = 2; // A single inset value to control teh sizing of the inner rect. using (Image offscreenImage = new Bitmap(this.Width, this.Height)) { using (Graphics offscreen = Graphics.FromImage(offscreenImage)) { Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(offscreen, rect); } rect.Inflate(new Size(-inset, -inset)); // Deflate inner rect. rect.Width = (int)(rect.Width * ((double)this.Value / this.Maximum)); if (rect.Width == 0) { rect.Width = 1; // Can't draw rec with width of 0. } LinearGradientBrush brush = new LinearGradientBrush(rect, this.BackColor, this.ForeColor, LinearGradientMode.Vertical); offscreen.FillRectangle(brush, inset, inset, rect.Width, rect.Height); e.Graphics.DrawImage(offscreenImage, 0, 0); offscreenImage.Dispose(); } } }
protected override void OnPaint(PaintEventArgs e) { const int inset = 0; // A single inset value to control teh sizing of the inner rect. using (Image offscreenImage = new Bitmap(this.Width, this.Height)) { using (Graphics offscreen = Graphics.FromImage(offscreenImage)) { Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); Rectangle rect2 = new Rectangle(0, 0, this.Width, this.Height); if (ProgressBarRenderer.IsSupported) { ProgressBarRenderer.DrawHorizontalBar(offscreen, rect); } rect.Inflate(new Size(-inset, -inset)); // Deflate inner rect. rect.Width = (int)(rect.Width * ((double)this.Value / this.Maximum)); if (rect.Width == 0) { rect.Width = 1; // Can't draw rec with width of 0. } SolidBrush brush = new SolidBrush(Color.FromArgb(3, 122, 204)); SolidBrush brush2 = new SolidBrush(Color.FromArgb(32, 32, 32)); offscreen.FillRectangle(brush2, inset, inset, rect2.Width, rect2.Height); offscreen.FillRectangle(brush, inset, inset, rect.Width, rect.Height); e.Graphics.DrawImage(offscreenImage, 0, 0); } } }