/// <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); }
/* * DrawBarGdiPlus */ /// <summary> /// Draws a bar within the specified rectangle with the specified color. /// </summary> /// <param name="g">A <c>System.Drawing.Graphics</c> to draw on.</param> /// <param name="rect">A <c>System.Drawing.RectangleF</c> to fit the bar in.</param> /// <param name="line">Incapsulates a graph line.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="line"/> is <see langword="null"/>.</para> /// </exception> protected virtual void DrawBarGdiPlus(Graphics g, RectangleF rect, NuGenGraphLine line) { if (g == null) { throw new ArgumentNullException("g"); } if (line == null) { throw new ArgumentNullException("line"); } using (SolidBrush sb = new SolidBrush(NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, line.LineColor))) { g.FillRectangle(sb, rect); } }
/// <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); } }
/* * DrawGraphGdiPlus */ /// <summary> /// Draws the graph. /// </summary> /// <param name="g">A <c>System.Drawing.Graphics</c> to draw on.</param> /// <param name="rect">A <c>System.Drawing.Rectangle</c> to fit the graph in.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// </exception> protected virtual void DrawGraphGdiPlus(Graphics g, Rectangle rect) { if (g == null) { throw new ArgumentNullException("g"); } int maxPoints = 0; if (this.maxCoords == -1) { /* Maximum push points not yet calculated. */ this.maxCoords = (rect.Width / this.Step) + 2 + ((rect.Width % this.Step > 0) ? 1 : 0); if (this.maxCoords <= 0) { this.maxCoords = 1; } } for (int lineIndex = 0; lineIndex < this.lines.Count; lineIndex++) { if (maxPoints < this.lines[lineIndex].Values.Count) { maxPoints = this.lines[lineIndex].Values.Count; } } if (maxPoints == 0 /* No lines to draw. */) { return; } for (int lineIndex = 0; lineIndex < this.lines.Count; lineIndex++) { /* * If the line has less push points than the line with the greatest * number of push points, new push points are appended with * the same value as the previous push point. If no push points * exist for the line, one is added with the least value possible. */ NuGenGraphLine pushGraphLine = this.lines[lineIndex]; if (pushGraphLine.Values.Count == 0) { pushGraphLine.Values.Add(this.Minimum); } while (pushGraphLine.Values.Count < maxPoints) { pushGraphLine.Values.Add(pushGraphLine.Values[pushGraphLine.Values.Count - 1]); } while (this.lines[lineIndex].Values.Count >= this.maxCoords) { this.lines[lineIndex].Values.RemoveAt(0); } if (this.lines[lineIndex].Values.Count == 0 /* No push points to draw. */) { return; } using (Pen p = new Pen(NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, (this.lines[lineIndex] as NuGenGraphLine).LineColor))) { PointF startPoint = PointF.Empty; PointF endPoint = PointF.Empty; if (pushGraphLine.IsBar) { startPoint = new PointF(rect.Left, rect.Height); } else { float initialValue = pushGraphLine.Values[0]; float percent = (float)(rect.Height - PEN_WIDTH) / (this.Maximum - this.Minimum); float relValue = (float)(rect.Height - PEN_WIDTH) - initialValue * percent; startPoint = new PointF(rect.Left, maxPoints == 1 ? rect.Height : relValue); } for (int valueIndex = 0; valueIndex < pushGraphLine.Values.Count; valueIndex++) { float xOffset = rect.Left + (valueIndex * this.Step); float initialValue = pushGraphLine.Values[valueIndex]; float percent = (float)rect.Height / (float)(this.Maximum - this.Minimum); float relValue = Math.Max(PEN_WIDTH * 2, (float)rect.Height - initialValue * percent); if (pushGraphLine.IsBar) { /* Draw a bar. */ RectangleF rectBar = new RectangleF( xOffset, relValue, this.Step, rect.Height ); this.DrawBarGdiPlus(g, rectBar, pushGraphLine); } else { /* Draw a line. */ endPoint = new PointF(xOffset, relValue); g.DrawLine(p, startPoint, endPoint); startPoint = endPoint; } } } } }
private void _controlPanel_Export(object sender, EventArgs e) { if (!NuGenArgument.IsValidDirectoryName(_pathSelector.SelectedPath)) { MessageBox.Show( string.Format(res.Argument_InvalidDirectory, new string(Path.GetInvalidPathChars())) , res.Message_Alert , MessageBoxButtons.OK , MessageBoxIcon.Exclamation ); return; } if (!NuGenArgument.IsValidFileName(_templateTextBox.Text)) { MessageBox.Show( string.Format(res.Argument_InvalidFilename, new string(Path.GetInvalidFileNameChars())) , res.Message_Alert , MessageBoxButtons.OK , MessageBoxIcon.Exclamation ); _templateTextBox.SelectAll(); _templateTextBox.Focus(); return; } this.SetExportStep(); Image[] images; if (_thumbnailContainer.SelectedImages.Count > 0) { images = new Image[_thumbnailContainer.SelectedImages.Count]; _thumbnailContainer.SelectedImages.CopyTo(images, 0); } else { images = new Image[_thumbnailContainer.Images.Count]; _thumbnailContainer.Images.CopyTo(images, 0); } this.SetExportParams( _exportProgressBar , images , _typeCombo.ImageType , _formatCombo.FileFormat , _numWatermarkCheckBox.Checked , _watermarkFontBlock.SelectedFont , NuGenControlPaint.ColorFromArgb(100 - _watermarkOpacitySpin.Value, _watermarkColorBox.SelectedColor) , _watermarkAlignDropDown.SelectedAlignment , _pathSelector.SelectedPath , _templateTextBox.Text ); MethodInvoker methodInvoker = new MethodInvoker(this.ExportImages); methodInvoker.BeginInvoke( new AsyncCallback( delegate { this.BeginInvoke( new MethodInvoker( delegate { this.SetFinishStep(); } ) ); } ) , null ); }