/// <summary> /// Draws the control. /// </summary> /// <param name="e">Provides data for the <c>System.Windows.Forms.Control.Paint</c> event.</param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; string bufferString = ""; // High quality text drawing. g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; // Define a tweaked rectangle for that the border was visible. Rectangle tweakedRectangle = new Rectangle( this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - PEN_WIDTH, this.ClientRectangle.Height - PEN_WIDTH ); /* * Text */ using (StringFormat sf = NuGenControlPaint.CreateStringFormat(this, this.TextAlign, this.EatLine, true)) { if (this.WordWrap == false) { sf.FormatFlags |= StringFormatFlags.NoWrap; } if (this.TextOrientation == NuGenOrientationStyle.Vertical) { sf.FormatFlags |= StringFormatFlags.DirectionVertical; } using (SolidBrush sb = new SolidBrush(this.ForeColor)) { g.DrawString( this.text, this.Font, sb, tweakedRectangle, sf ); } } /* * Border */ NuGenControlPaint.DrawBorder(g, this.ClientRectangle, NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, this.BorderColor), this.BorderStyle); }
/* * RenderUsingGdi */ /// <summary> /// Renders this <see cref="T:Genetibase.UI.NuGenMeters.NuGenPushGraphBar"/> using native GDI algorythms. /// </summary> /// <param name="g">Specifies a GDI+ drawing surface.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// </exception> protected virtual void RenderUsingGdi(Graphics g) { if (g == null) { throw new ArgumentNullException("g"); } IntPtr paintDC = g.GetHdc(); /* First we crate the back buffer. */ IntPtr dc = this.InitBackBuffer(paintDC); /* Ensure we don't draw out of our client rectangle. */ Gdi32.IntersectClipRect(dc, this.ClientRectangle); /* Fill the background. */ RECT rect = (RECT)this.ClientRectangle; User32.FillSolidRect(dc, ref rect, this.BackgroundColor); Gdi32.SetBkMode(dc, Gdi32.TRANSPARENT); /* * DrawGrid */ if (this.ShowGrid) { this.DrawGridGdi(dc, this.ClientRectangle, this.GridColor, this.GridStep); } /* * DrawGraph */ this.DrawGraphGdi(dc, this.ClientRectangle); this.FreeBackBuffer(paintDC); g.ReleaseHdc(paintDC); NuGenControlPaint.DrawBorder(g, this.ClientRectangle, this.BorderColor, this.BorderStyle); }
/// <summary> /// Draws the control. /// </summary> /// <param name="e">Provides data for the <c>System.Windows.Forms.Control.Paint</c> event.</param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; string bufferString = ""; if (this.UseClearTypeTextRendering) { // High quality text drawing. g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; } // Define a tweaked rectangle for that the border was visible. Rectangle tweakedRectangle = new Rectangle( this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - PEN_WIDTH, this.ClientRectangle.Height - PEN_WIDTH ); /* * Text */ StringFormat sf = new StringFormat(); sf.Alignment = this.TextAlignment; sf.LineAlignment = this.TextLineAlignment; if (this.WordWrap == false) { sf.FormatFlags = StringFormatFlags.NoWrap; } if (this.TextOrientation == NuGenOrientationStyle.Vertical) { sf.FormatFlags = StringFormatFlags.DirectionVertical; } if (this.AutoSize == false && this.WordWrap == false && this.EatLine == true) { Debug.Assert(this.StringProcessor != null, "this.StringProcessor != null"); bufferString = this.StringProcessor.EatLine( this.Text, this.Font, (this.TextOrientation == NuGenOrientationStyle.Vertical) ? tweakedRectangle.Height : tweakedRectangle.Width, g ); } else { bufferString = this.Text; } using (SolidBrush sb = new SolidBrush(this.ForeColor)) { g.DrawString(bufferString, this.Font, sb, tweakedRectangle, sf); } /* * Border */ NuGenControlPaint.DrawBorder(g, this.ClientRectangle, NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, this.BorderColor), this.BorderStyle); }
/// <summary> /// Draws the control. /// </summary> /// <param name="e">Provides data for the <c>System.Windows.Forms.Control.Paint</c> event.</param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; // High quality drawing. g.SmoothingMode = SmoothingMode.AntiAlias; // Define a tweaked rectangle for that the border was visible. Rectangle tweakedRectangle = new Rectangle( this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - PEN_WIDTH, this.ClientRectangle.Height - PEN_WIDTH ); if (this.Orientation == NuGenOrientationStyle.Vertical) { g.TranslateTransform(0, tweakedRectangle.Height); g.RotateTransform(-90); int w = 0; w = tweakedRectangle.Width; tweakedRectangle.Width = tweakedRectangle.Height; tweakedRectangle.Height = w; } /* * Background. */ if (this.BackgroundImage == null) { switch (this.BackgroundStyle) { case NuGenBackgroundStyle.Gradient: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackGradientStartColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackGradientEndColor), 90 )) { g.FillRectangle(lgb, tweakedRectangle); } break; case NuGenBackgroundStyle.VerticalGradient: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackGradientStartColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackGradientEndColor), 360 )) { g.FillRectangle(lgb, tweakedRectangle); } break; case NuGenBackgroundStyle.Tube: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackTubeGradientStartColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackTubeGradientEndColor), 90 )) { ColorBlend colorBlend = new ColorBlend(3); colorBlend.Colors = new Color[] { Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackTubeGradientEndColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackTubeGradientStartColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.BackgroundTransparency), this.BackTubeGradientEndColor) }; colorBlend.Positions = new float[] { 0.0f, 0.5f, 1.0f }; lgb.InterpolationColors = colorBlend; g.FillRectangle(lgb, tweakedRectangle); } break; } } else { if (this.StretchImage) { g.DrawImage( this.BackgroundImage, tweakedRectangle, 0, 0, this.BackgroundImage.Width, this.BackgroundImage.Height, GraphicsUnit.Pixel, NuGenControlPaint.GetTransparentImageAttributes(this.BackgroundTransparency, false) ); } else { g.DrawImage( this.BackgroundImage, tweakedRectangle, tweakedRectangle.X, tweakedRectangle.Y, tweakedRectangle.Width, tweakedRectangle.Height, GraphicsUnit.Pixel, NuGenControlPaint.GetTransparentImageAttributes(this.BackgroundTransparency, true) ); } } /* * Foreground. */ switch (this.ForegroundStyle) { case NuGenBackgroundStyle.Constant: using (SolidBrush sb = new SolidBrush(this.ForeColor)) { g.FillRectangle(sb, new RectangleF( tweakedRectangle.X, tweakedRectangle.Y, tweakedRectangle.Width / this.Maximum * this.Value, tweakedRectangle.Height) ); } break; case NuGenBackgroundStyle.Gradient: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.GradientStartColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.GradientEndColor), 90)) { g.FillRectangle(lgb, new RectangleF( tweakedRectangle.X, tweakedRectangle.Y, tweakedRectangle.Width / (float)this.Maximum * this.Value, tweakedRectangle.Height) ); } break; case NuGenBackgroundStyle.VerticalGradient: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.GradientStartColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.GradientEndColor), 360 )) { g.FillRectangle(lgb, new RectangleF( tweakedRectangle.X, tweakedRectangle.Y, tweakedRectangle.Width / this.Maximum * this.Value, tweakedRectangle.Height) ); } break; case NuGenBackgroundStyle.Tube: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.TubeGradientStartColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.TubeGradientEndColor), 90 )) { ColorBlend colorBlend = new ColorBlend(3); colorBlend.Colors = new Color[] { Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.TubeGradientEndColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.TubeGradientStartColor), Color.FromArgb(NuGenControlPaint.GetAlphaChannel(this.ForegroundTransparency), this.TubeGradientEndColor) }; colorBlend.Positions = new float[] { 0.0f, 0.5f, 1.0f }; lgb.InterpolationColors = colorBlend; g.FillRectangle(lgb, new RectangleF( tweakedRectangle.X, tweakedRectangle.Y, tweakedRectangle.Width / this.Maximum * this.Value, tweakedRectangle.Height) ); } break; } /* * TickLine. */ if (this.TickLine && this.PreviousMaximum != 0.0f && this.PreviousMaximum != this.Maximum && this.PreviousMaximum != this.Value) { if (this.Orientation == NuGenOrientationStyle.Horizontal) { NuGenControlPaint.DrawReversibleLine( g, (int)((float)this.ClientRectangle.Width / this.Maximum * this.PreviousMaximum), this.ClientRectangle.Top + PEN_WIDTH, (int)((float)this.ClientRectangle.Width / this.Maximum * this.PreviousMaximum), this.ClientRectangle.Bottom - PEN_WIDTH * 2 ); } else { NuGenControlPaint.DrawReversibleLine( g, this.ClientRectangle.Left + PEN_WIDTH * 2, (int)((float)this.ClientRectangle.Height - (float)this.ClientRectangle.Height / this.Maximum * this.PreviousMaximum), this.ClientRectangle.Right - PEN_WIDTH * 2, (int)((float)this.ClientRectangle.Height - (float)this.ClientRectangle.Height / this.Maximum * this.PreviousMaximum) ); } } /* * Border. */ switch (this.BorderStyle) { case NuGenBorderStyle.Dashed: case NuGenBorderStyle.Dotted: case NuGenBorderStyle.Solid: Rectangle borderRectangle = new Rectangle( tweakedRectangle.Left, tweakedRectangle.Top, tweakedRectangle.Right + PEN_WIDTH, tweakedRectangle.Bottom + PEN_WIDTH ); NuGenControlPaint.DrawBorder(g, borderRectangle, NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, this.BorderColor), this.BorderStyle); break; default: g.ResetTransform(); NuGenControlPaint.DrawBorder(g, this.ClientRectangle, NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, this.BorderColor), this.BorderStyle); break; } /* * Grayscale. */ if (this.Enabled == false) { Image img = NuGenControlPaint.CreateBitmapFromGraphics(g, this.ClientRectangle); if (this.Orientation == NuGenOrientationStyle.Vertical) { g.ResetTransform(); } ControlPaint.DrawImageDisabled(g, img, 0, 0, this.BackColor); } }
/* * RenderUsingGdiPlus */ /// <summary> /// Renders this <see cref="T:Genetibase.UI.NuGenMeters.NuGenPushGraphBar"/> using GDI+ algorythms. /// </summary> /// <param name="g">Specifies a GDI+ drawing surface.</param> protected virtual void RenderUsingGdiPlus(Graphics g) { if (g == null) { throw new ArgumentNullException("g"); } // High quality drawing. g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle tweakedRectangle = new Rectangle( this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - PEN_WIDTH, this.ClientRectangle.Height - PEN_WIDTH * 3 ); /* * Background. */ if (this.BackgroundImage == null) { switch (this.BackgroundStyle) { case NuGenBackgroundStyle.Gradient: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackGradientStartColor), NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackGradientEndColor), 90 )) { g.FillRectangle(lgb, this.ClientRectangle); } break; case NuGenBackgroundStyle.Tube: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackTubeGradientStartColor), NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackTubeGradientEndColor), 90 )) { ColorBlend colorBlend = new ColorBlend(3); colorBlend.Colors = new Color[] { NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackTubeGradientEndColor), NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackTubeGradientStartColor), NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackTubeGradientEndColor) }; colorBlend.Positions = new float[] { 0.0f, 0.5f, 1.0f }; lgb.InterpolationColors = colorBlend; g.FillRectangle(lgb, this.ClientRectangle); } break; case NuGenBackgroundStyle.VerticalGradient: using (LinearGradientBrush lgb = new LinearGradientBrush( tweakedRectangle, NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackGradientStartColor), NuGenControlPaint.ColorFromArgb(this.BackgroundTransparency, this.BackGradientEndColor), 360 )) { g.FillRectangle(lgb, this.ClientRectangle); } break; } } else { if (this.StretchImage) { g.DrawImage( this.BackgroundImage, tweakedRectangle, 0, 0, this.BackgroundImage.Width, this.BackgroundImage.Height, GraphicsUnit.Pixel, NuGenControlPaint.GetTransparentImageAttributes(this.BackgroundTransparency, false) ); } else { g.DrawImage( this.BackgroundImage, tweakedRectangle, tweakedRectangle.X, tweakedRectangle.Y, tweakedRectangle.Width, tweakedRectangle.Height, GraphicsUnit.Pixel, NuGenControlPaint.GetTransparentImageAttributes(this.BackgroundTransparency, true) ); } } /* * Grid. */ if (this.ShowGrid) { this.DrawGridGdiPlus(g, tweakedRectangle, NuGenControlPaint.ColorFromArgb(this.GridTransparency, this.GridColor), this.GridStep); } /* * Graph. */ this.DrawGraphGdiPlus(g, tweakedRectangle); /* * Border. */ NuGenControlPaint.DrawBorder(g, this.ClientRectangle, NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, this.BorderColor), this.BorderStyle); /* * Grayscale. */ if (this.Enabled == false) { Image img = NuGenControlPaint.CreateBitmapFromGraphics(g, this.ClientRectangle); ControlPaint.DrawImageDisabled(g, img, 0, 0, this.BackColor); } }