/// <summary> /// Draws aligned to width text on the angle. /// </summary> /// <param name="g">Graphics to draw on.</param> /// <param name="text">Text to draw on.</param> /// <param name="font">Font to draw on.</param> /// <param name="brush">Brush to draw.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="stringFormat">Text format.</param> /// <param name="angle">Show text at an angle.</param> public static void DrawStringWidth(Graphics g, string text, Font font, Brush brush, RectangleD rect, StringFormat stringFormat, float angle) { if (angle != 0) { var svClip = g.Clip; g.SetClip(rect.ToRectangleF(), CombineMode.Intersect); var gs = g.Save(); g.TranslateTransform((float)(rect.Left + rect.Width / 2), (float)(rect.Top + rect.Height / 2)); g.RotateTransform((float)angle); rect.X = -rect.Width / 2; rect.Y = -rect.Height / 2; var drawRect = new RectangleD(rect.X, rect.Y, rect.Width, rect.Height); if ((angle > 45 && angle < 135) || (angle > 225 && angle < 315)) { drawRect = new RectangleD(rect.Y, rect.X, rect.Height, rect.Width); } DrawStringWidth(g, text, font, brush, drawRect, stringFormat); g.Restore(gs); g.SetClip(svClip, CombineMode.Replace); } else { DrawStringWidth(g, text, font, brush, rect, stringFormat); } }
/// <summary> /// Draws text at an angle. /// </summary> /// <param name="g">Graphics to draw on.</param> /// <param name="text">Text to draw on.</param> /// <param name="font">Font to draw on.</param> /// <param name="brush">Brush to draw.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="stringFormat">Text format.</param> /// <param name="angle">Show text at an angle.</param> public static void DrawString(Graphics g, string text, Font font, Brush brush, RectangleD rect, StringFormat stringFormat, float angle) { try { if (angle != 0) { var svClip = g.Clip; g.SetClip(rect.ToRectangleF(), CombineMode.Intersect); var gs = g.Save(); g.TranslateTransform((float)(rect.Left + rect.Width / 2), (float)(rect.Top + rect.Height / 2)); g.RotateTransform(-(float)angle); rect.X = -rect.Width / 2; rect.Y = -rect.Height / 2; var drawRect = new RectangleD(rect.X, rect.Y, rect.Width, rect.Height); if ((angle > 45 && angle < 135) || (angle > 225 && angle < 315)) { drawRect = new RectangleD(rect.Y, rect.X, rect.Height, rect.Width); } if (angle == 0 || angle == 90 || angle == 180 || angle == 270) { g.DrawString(text, font, brush, drawRect.ToRectangleF(), stringFormat); } else { stringFormat.SetTabStops(20f, new float[] { 30f, 30f, 30f }); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; g.DrawString(text, font, brush, (float)(drawRect.X + drawRect.Width / 2), (float)(drawRect.Y + drawRect.Height / 2), stringFormat); } g.Restore(gs); g.SetClip(svClip, CombineMode.Replace); } else { g.DrawString(text, font, brush, rect.ToRectangleF(), stringFormat); } } catch { } }
/// <summary> /// Fills the interior of a rectangle specified by a RectangleD structure. /// </summary> /// <param name="g">The Graphics to draw on.</param> /// <param name="brush">Brush object that determines the characteristics of the fill.</param> /// <param name="rect">RectangleD structure that represents the rectangle to fill.</param> public static void FillRectangle(Graphics g, Brush brush, RectangleD rect) { if (brush is SolidBrush) { if (((SolidBrush)brush).Color == Color.Transparent) { return; } } g.FillRectangle(brush, rect.ToRectangleF()); }
/// <summary> /// Draws the text aligned to width. /// </summary> /// <param name="g">Graphics to draw on.</param> /// <param name="text">Text to draw on.</param> /// <param name="font">Font to draw on.</param> /// <param name="brush">Brush to draw on.</param> /// <param name="rect">Rectangle to draw on.</param> /// <param name="stringFormat">Text format.</param> public static void DrawStringWidth(Graphics g, string text, Font font, Brush brush, RectangleD rect, StringFormat stringFormat) { Region svClip = g.Clip; g.SetClip(rect.ToRectangleF(), CombineMode.Intersect); if (!string.IsNullOrEmpty(text)) { if ((stringFormat.FormatFlags & StringFormatFlags.NoWrap) > 0) { stringFormat.FormatFlags ^= StringFormatFlags.NoWrap; } var ranges = GetRange(g, rect, text, font, stringFormat); stringFormat.LineAlignment = StringAlignment.Near; stringFormat.FormatFlags |= StringFormatFlags.LineLimit; for (int k = 0; k < ranges.Length; k++) { if (ranges[k].IsStart) { stringFormat.Alignment = StringAlignment.Near; } else if (ranges[k].IsEnd) { stringFormat.Alignment = StringAlignment.Far; } else { stringFormat.Alignment = StringAlignment.Center; } g.DrawString(ranges[k].Text, font, brush, (new RectangleD(ranges[k].Pos, ranges[k].Size)).ToRectangleF(), stringFormat); /* * g.DrawRectangle(Pens.Red, * (float)ranges[k].Pos.X, * (float)ranges[k].Pos.Y, * (float)ranges[k].Size.Width, * (float)ranges[k].Size.Height); */ } } g.SetClip(svClip, CombineMode.Replace); }
/// <summary> /// Draws this border on the indicated Graphics. /// </summary> /// <param name="g">Graphics on which a border can be drawn.</param> /// <param name="rect">The rectangle that indicates an area of the border drawing.</param> /// <param name="zoom">The scale of a border to draw.</param> /// <param name="emptyColor">The color of space between double lines (used only when border style equal Double).</param> public void Draw(Graphics g, RectangleD rect, double zoom, Color emptyColor) { Draw(g, rect.ToRectangleF(), (float)zoom, emptyColor); }
/// <summary> /// Returns the standard brush from the report brush. /// </summary> /// <param name="brush">Report brush.</param> /// <param name="rect">Rectangle for gradient.</param> /// <returns>Gdi brush.</returns> public static Brush GetBrush(StiBrush brush, RectangleD rect) { if (brush is StiEmptyBrush) { return(new SolidBrush(Color.Transparent)); } else if (brush is StiSolidBrush) { return(new SolidBrush(((StiSolidBrush)brush).Color)); } else if (brush is StiGradientBrush) { RectangleF rectF = rect.ToRectangleF(); if (rectF.Width < 1) { rectF.Width = 1; } if (rectF.Height < 1) { rectF.Height = 1; } StiGradientBrush gradientBrush = brush as StiGradientBrush; return(new LinearGradientBrush(rectF, gradientBrush.StartColor, gradientBrush.EndColor, (float)gradientBrush.Angle)); } else if (brush is StiHatchBrush) { StiHatchBrush hatchBrush = brush as StiHatchBrush; return(new HatchBrush(hatchBrush.Style, hatchBrush.ForeColor, hatchBrush.BackColor)); } else if (brush is StiGlareBrush) { RectangleF rectF = rect.ToRectangleF(); if (rectF.Width < 1) { rectF.Width = 1; } if (rectF.Height < 1) { rectF.Height = 1; } StiGlareBrush glareBrush = brush as StiGlareBrush; LinearGradientBrush br = new LinearGradientBrush(rectF, glareBrush.StartColor, glareBrush.EndColor, (float)glareBrush.Angle); br.SetSigmaBellShape(glareBrush.Focus, glareBrush.Scale); return(br); } else if (brush is StiGlassBrush) { Bitmap bmp = new Bitmap((int)rect.Width + 1, (int)rect.Height + 1); using (Graphics gg = Graphics.FromImage(bmp)) { ((StiGlassBrush)brush).Draw(gg, new RectangleF(0, 0, (float)rect.Width + 1, (float)rect.Height + 1)); } TextureBrush textureBrush = new TextureBrush(bmp); textureBrush.TranslateTransform((float)rect.X, (float)rect.Y); return(textureBrush); } return(null); }