private void DrawPointerDown(Graphics g) { Point[] points = new Point[] { new Point(ThumbBounds.Left + (ThumbBounds.Width / 2), ThumbBounds.Bottom - 1), new Point(ThumbBounds.Left, (ThumbBounds.Bottom - (ThumbBounds.Width / 2)) - 1), ThumbBounds.Location, new Point(ThumbBounds.Right - 1, ThumbBounds.Top), new Point(ThumbBounds.Right - 1, (ThumbBounds.Bottom - (ThumbBounds.Width / 2)) - 1), new Point(ThumbBounds.Left + (ThumbBounds.Width / 2), ThumbBounds.Bottom - 1) }; GraphicsPath path = new GraphicsPath(); path.AddLines(points); Region region = new Region(path); g.Clip = region; if (ThumbState == 3 || !base.Enabled) ControlPaint.DrawButton(g, ThumbBounds, ButtonState.All); else g.Clear(SystemColors.Control); g.ResetClip(); region.Dispose(); path.Dispose(); Point[] pointArray2 = new Point[] { points[0], points[1], points[2], points[3] }; g.DrawLines(SystemPens.ControlLightLight, pointArray2); pointArray2 = new Point[] { points[3], points[4], points[5] }; g.DrawLines(SystemPens.ControlDarkDark, pointArray2); points[0].Offset(0, -1); points[1].Offset(1, 0); points[2].Offset(1, 1); points[3].Offset(-1, 1); points[4].Offset(-1, 0); points[5] = points[0]; pointArray2 = new Point[] { points[0], points[1], points[2], points[3] }; g.DrawLines(SystemPens.ControlLight, pointArray2); pointArray2 = new Point[] { points[3], points[4], points[5] }; g.DrawLines(SystemPens.ControlDark, pointArray2); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics G = e.Graphics; LinearGradientBrush linearGradientBrush1 = new LinearGradientBrush(//创建线性渐变画刷 new Point(0, 0),new Point(20, 20), //渐变起始点和终止点 Color.Yellow,Color.Blue); //渐变起始颜色和终止颜色 G.FillRectangle(linearGradientBrush1, new Rectangle(0, 0, 150, 150));//绘制矩形 LinearGradientBrush linearGradientBrush2 = new LinearGradientBrush(//创建线性渐变画刷 new Rectangle(0, 0, 20, 20), //渐变所在矩形 Color.Yellow, Color.Blue, 60f); //渐变起始颜色、终止颜色以及渐变方向 linearGradientBrush2.WrapMode = WrapMode.TileFlipXY; G.FillRectangle(linearGradientBrush2, new Rectangle(150, 0, 150, 150));//绘制矩形 GraphicsPath graphicsPath1 = new GraphicsPath(); //创建绘制路径 graphicsPath1.AddArc(new Rectangle(0, 150, 100, 100), 90, 180);//向路径中添加半左圆弧 graphicsPath1.AddArc(new Rectangle(150, 150, 100, 100), 270, 180);//向路径中添加半右圆弧 graphicsPath1.CloseFigure(); //闭合路径 PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath1);//创建路径渐变画刷 pathGradientBrush.CenterColor = Color.Yellow; //指定画刷中心颜色 pathGradientBrush.SurroundColors = new Color[] { Color.Blue };//指定画刷周边颜色 pathGradientBrush.CenterPoint = new PointF(125, 200); //指定画刷中心点坐标 G.SmoothingMode = SmoothingMode.AntiAlias; //消锯齿 G.FillPath(pathGradientBrush, graphicsPath1); //利用画刷填充路径 G.DrawPath(new Pen(Color.Lime, 3f), graphicsPath1); //绘制闭合路径曲线 linearGradientBrush1.Dispose(); linearGradientBrush2.Dispose(); graphicsPath1.Dispose(); pathGradientBrush.Dispose(); }
public static Bitmap BitmapFromText(string text, Font f, Color col, Color glowCol, Rectangle rect, float glowScale) { Bitmap bm = new Bitmap((int)(rect.Width / glowScale), (int)(rect.Height / glowScale)); GraphicsPath pth = new GraphicsPath(); pth.AddString(text, f.FontFamily, (int)f.Style, f.Size, new Point(rect.Left, rect.Top), StringFormat.GenericTypographic); Graphics g = Graphics.FromImage(bm); Matrix mx = new Matrix(1.0f / glowScale, 0, 0, 1.0f / glowScale, -(1.0f / glowScale), -(1.0f / glowScale)); g.SmoothingMode = SmoothingMode.AntiAlias; g.Transform = mx; Pen p = new Pen(glowCol, 3); g.DrawPath(p, pth); g.FillPath(new SolidBrush(glowCol), pth); g.Dispose(); Bitmap bmp = new Bitmap(rect.Width, rect.Height); Graphics g2 = Graphics.FromImage(bmp); g2.Transform = new Matrix(1, 0, 0, 1, 50, 50); g2.SmoothingMode = SmoothingMode.AntiAlias; g2.InterpolationMode = InterpolationMode.HighQualityBicubic; g2.DrawImage(bm, rect, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel); g2.FillPath(new SolidBrush(col), pth); pth.Dispose(); return bmp; }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics myGraphics = e.Graphics; Pen myPen = new Pen(Color.Black, 1.0f); GraphicsPath gp = new GraphicsPath(); Matrix RotationTransform; float centerX = this.Size.Width / 2f; float centerY = this.Size.Height / 2f; gp.AddPolygon(new PointF[] { new PointF(centerX, centerY - 5), new PointF(centerX-5, centerY + 5), new PointF(centerX+5, centerY + 5) }); RotationTransform = new Matrix(1, 0, 0, 1, 0, 0); // rotation matrix PointF RotationPoint = new PointF(centerX, centerY); // rotation point RotationTransform.RotateAt(heading, RotationPoint); gp.Transform(RotationTransform); myGraphics.FillPath(myPen.Brush, gp); myGraphics.DrawPath(myPen, gp); myPen.Dispose(); gp.Dispose(); }
void FormSplashScreen_Paint(object sender, PaintEventArgs e) { if ( Natives.CanUseAero ) { Natives.FillBlackRegion(e.Graphics, ClientRectangle); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; var gDevPath = new GraphicsPath(); var gLogPath = new GraphicsPath(); var brush = new SolidBrush(Color.FromArgb(0x99, Color.Black)); gDevPath.AddString(_devList, DrawingFont.FontFamily, (int)FontStyle.Regular, Constants.DEV_TEXT_SIZE, new Point(Constants.LOGO_WIDTH + Constants.PADDING, Constants.TEXT_HEIGHT + Constants.PADDING), StringFormat.GenericDefault); gLogPath.AddString(LogMessage, DrawingFont.FontFamily, (int)FontStyle.Bold, Constants.LOG_TEXT_SIZE, new Point(Constants.PADDING, Height - 65 - Constants.PADDING), StringFormat.GenericDefault); e.Graphics.DrawImage(HammerBitmap, Constants.PADDING, Constants.PADDING, Constants.LOGO_WIDTH, Constants.LOGO_HEIGHT); e.Graphics.DrawImage(MCForgeBitmap, Constants.LOGO_WIDTH + Constants.PADDING, Constants.PADDING, Constants.TEXT_WIDTH, Constants.TEXT_HEIGHT); e.Graphics.FillPath(brush, gDevPath); e.Graphics.FillPath(brush, gLogPath); gDevPath.Dispose(); gLogPath.Dispose(); brush.Dispose(); } }
/// <summary> /// The graphics device and clip rectangle are in the parent coordinates. /// </summary> /// <param name="g"></param> /// <param name="clipRectangle"></param> /// <param name="symbol">The symbol to use for drawing.</param> public void Draw(Graphics g, Rectangle clipRectangle, ISymbol symbol) { Color topLeft; Color bottomRight; if (_isSelected) { topLeft = _selectionColor.Darker(.3F); bottomRight = _selectionColor.Lighter(.3F); } else { topLeft = _backColor.Lighter(.3F); bottomRight = _backColor.Darker(.3F); } LinearGradientBrush b = new LinearGradientBrush(_bounds, topLeft, bottomRight, LinearGradientMode.ForwardDiagonal); GraphicsPath gp = new GraphicsPath(); gp.AddRoundedRectangle(Bounds, _roundingRadius); g.FillPath(b, gp); gp.Dispose(); b.Dispose(); Matrix old = g.Transform; Matrix shift = g.Transform; shift.Translate(_bounds.Left + _bounds.Width / 2, _bounds.Top + _bounds.Height / 2); g.Transform = shift; if (symbol != null) { OnDrawSymbol(g, symbol); } g.Transform = old; }
//public static GraphicsPath GetBottomRoundRect(RectangleF r, int offset) //{ // int left = Math.Min((int)r.Left, (int)r.Right); // int right = Math.Max((int)r.Left, (int)r.Right); // int top = Math.Min((int)r.Top, (int)r.Bottom); // int bottom = Math.Max((int)r.Top, (int)r.Bottom); // GraphicsPath path = new GraphicsPath(); // path.AddLine(r.Right, r.Top, r.Right, r.Top); // path.AddArc(right - offset, bottom - offset, offset, offset, 0.0f, 90.0f); // path.AddArc(left, bottom - offset, offset, offset, 90.0f, 90.0f); // path.AddLine(r.Left, r.Top, r.Left, r.Top); // path.CloseFigure(); // return path; //} public static GraphicsPath GetTopRoundedRect(RectangleF r, int offset) { int left = Math.Min((int)r.Left, (int)r.Right); int right = Math.Max((int)r.Left, (int)r.Right); int top = Math.Min((int)r.Top, (int)r.Bottom); int bottom = Math.Max((int)r.Top, (int)r.Bottom); GraphicsPath path = new GraphicsPath(); try { path.AddArc(right - offset, top, offset, offset, 270.0f, 90.0f); path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom); path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom); path.AddArc(left, top, offset, offset, 180.0f, 90.0f); path.CloseFigure(); return path; } catch { path.Dispose(); throw; } }
public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius) { Y+=5; X+=5; width -= 12; height -= 12; GraphicsPath gp = new GraphicsPath(); gp.AddLine(X + radius, Y, X + width - (radius * 2), Y); gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2)); gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height); gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); gp.AddLine(X, Y + height - (radius * 2), X, Y + radius); gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90); gp.CloseFigure(); g.FillPath(Brushes.Transparent, gp); gp.Dispose(); gp = new GraphicsPath(); gp.AddLine(X + radius, Y, X + width - (radius * 2), Y); gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2)); gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height); gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); gp.AddLine(X, Y + height - (radius * 2), X, Y + radius); gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90); gp.CloseFigure(); g.DrawPath(p, gp); gp.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.HighQuality; Rectangle bounds = new Rectangle(0, 0, Width, Height); bounds.Width = Width - 1; bounds.Height -= 1; int arcSize = 10; GraphicsPath path = new GraphicsPath(); AddRoundedRectangle(path, bounds, arcSize); using (SolidBrush brush = new SolidBrush(Renderer.BackColor)) { g.FillPath(brush, path); } using (Pen pen = new Pen(Renderer.BorderPenColor)) { g.DrawPath(pen, path); } path.Dispose(); }
public static void WarpPath(GraphicsPath path, PointF[] destPoints, RectangleF srcRect, Matrix matrix = null, WarpMode warpMode = WarpMode.Perspective, float flatness = 0.25f) { if (path.PointCount == 0) return; path.Flatten(matrix, flatness); var pathData = path.PathData; var pnts = path.PathPoints; var srcPoints = new PointF[] { new PointF(srcRect.Left, srcRect.Top), new PointF(srcRect.Right, srcRect.Top), new PointF(srcRect.Left, srcRect.Bottom), new PointF(srcRect.Right, srcRect.Bottom) }; var count = pnts.Length; float x1, y1; int i; if (warpMode == WarpMode.Perspective) { CalcProjectiveXformCoeffs(srcPoints, destPoints, out coeffs); for (i = 0; i < count; i++) { x1 = pnts[i].X; y1 = pnts[i].Y; var factor = 1.0f / (coeffs[6] * x1 + coeffs[7] * y1 + 1.0f); pnts[i].X = (float)(factor * (coeffs[0] * x1 + coeffs[1] * y1 + coeffs[2])); pnts[i].Y = (float)(factor * (coeffs[3] * x1 + coeffs[4] * y1 + coeffs[5])); } } else { CalcBilinearXformCoeffs(srcPoints, destPoints, out coeffs); for (i = 0; i < count; i++) { x1 = pnts[i].X; y1 = pnts[i].Y; pnts[i].X = (float)(coeffs[0] * x1 + coeffs[1] * y1 + coeffs[2] * x1 * y1 + coeffs[3]); pnts[i].Y = (float)(coeffs[4] * x1 + coeffs[5] * y1 + coeffs[6] * x1 * y1 + coeffs[7]); } } GraphicsPath warpedPath = new GraphicsPath(pnts, pathData.Types); if (warpedPath != null) { FillMode fm = path.FillMode; path.Reset(); path.FillMode = fm; path.AddPath(warpedPath, true); warpedPath.Dispose(); } }
public void HandlePaintEvent(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Point topLeft = new Point() { X = (_control.GetClientRectangleWidth() - _currentLength) / 2, Y = (_control.GetClientRectangleHeight() - _currentLength) / 2 }; Point bottomRight = new Point() { X = (_control.GetClientRectangleWidth() + _currentLength) / 2, Y = (_control.GetClientRectangleHeight() + _currentLength) / 2 }; //Only update brush if previousLength != currentLength. When control is resized, keep the current brush if tick event hasn't happened yet if (_previousLength != _currentLength) { if (_currentBrush == null) _currentBrush = new HatchBrush(HatchStyle.Percent90, Color.Red); else if (_currentBrush is HatchBrush) { _currentBrush.Dispose(); _currentBrush = new LinearGradientBrush(topLeft, bottomRight, Color.Green, Color.GreenYellow); } else if (_currentBrush is LinearGradientBrush) { // Create the path (which determines the shape of the gradient). GraphicsPath path = new GraphicsPath(); path.AddRectangle(new Rectangle(topLeft.X, bottomRight.Y, _currentLength, _currentLength)); _currentBrush.Dispose(); _currentBrush = new PathGradientBrush(path); ((PathGradientBrush)_currentBrush).WrapMode = WrapMode.Tile; ((PathGradientBrush)_currentBrush).SurroundColors = new Color[] { Color.White }; ((PathGradientBrush)_currentBrush).CenterColor = Color.Blue; path.Dispose(); } else { _currentBrush.Dispose(); _currentBrush = new HatchBrush(HatchStyle.Percent90, Color.Red); } } Pen drawingPen = new Pen(Color.Black, 2); g.DrawRectangle(drawingPen, topLeft.X, topLeft.Y, _currentLength, _currentLength); g.FillRectangle(_currentBrush, topLeft.X, topLeft.Y, _currentLength, _currentLength); //Free memory drawingPen.Dispose(); //Update previousLength _previousLength = _currentLength; }
public virtual void DrawCommandButton(NodeCommandPartRendererEventArgs info) { bool mouseOver = (info.Node.MouseOverNodePart == eMouseOverNodePart.Command); CommandColors c=new CommandColors(); if(mouseOver) { c.BackColor = info.MouseOverBackColor; c.BackColor2 = info.MouseOverBackColor2; c.BackColorGradientAngle = info.MouseOverBackColorGradientAngle; c.ForeColor = info.MouseOverForeColor; } else { c.BackColor = info.BackColor; c.BackColor2 = info.BackColor2; c.BackColorGradientAngle = info.BackColorGradientAngle; c.ForeColor = info.ForeColor; } Rectangle fillBounds = info.CommandPartBounds; fillBounds.Width--; fillBounds.Height--; Region oldRegion = info.Graphics.Clip.Clone() as Region; info.Graphics.SetClip(fillBounds,CombineMode.Intersect); if(c.BackColor2.IsEmpty) { if(!c.BackColor.IsEmpty) { using(SolidBrush brush=new SolidBrush(c.BackColor)) info.Graphics.FillRectangle(brush,fillBounds); } } else { using(LinearGradientBrush brush=DisplayHelp.CreateLinearGradientBrush(info.CommandPartBounds, c.BackColor, c.BackColor2, c.BackColorGradientAngle)) info.Graphics.FillRectangle(brush,fillBounds); } if(c.ForeColor.IsEmpty) return; int width=6; int height=3; GraphicsPath path=new GraphicsPath(); Point p=new Point(info.CommandPartBounds.X+(info.CommandPartBounds.Width-width)/2,info.CommandPartBounds.Y+(info.CommandPartBounds.Height-height)/2); path.AddLine(p.X, p.Y, p.X+width,p.Y); path.AddLine(p.X+width,p.Y,p.X+width/2,p.Y+height); path.AddLine(p.X, p.Y,p.X+width/2,p.Y+height); path.CloseAllFigures(); using(SolidBrush brush=new SolidBrush(c.ForeColor)) info.Graphics.FillPath(brush,path); path.Dispose(); info.Graphics.Clip = oldRegion; }
private void Form2_Load(object sender, EventArgs e) { GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(pic1.ClientRectangle); Region region = new Region(gp); pic1.Region = region; gp.Dispose(); region.Dispose(); }
public void Draw(Graphics g, Color c) { GraphicsPath path = new GraphicsPath(); path.AddPolygon(m_HexagonPoints); using (SolidBrush brush = new SolidBrush(c)) { g.FillPath(brush, path); } path.Dispose(); }
/// <summary> /// Handles the drawing code, extending it to include some outline content. /// </summary> /// <param name="g"></param> /// <param name="scaleSize"></param> protected override void OnDraw(Graphics g, double scaleSize) { base.OnDraw(g, scaleSize); float dx = (float)(Size.Width * scaleSize / 2); float dy = (float)(Size.Height * scaleSize / 2); GraphicsPath gp = new GraphicsPath(); gp.AddRectangle(new RectangleF(-dx, -dy, 2F * dx, 2f * dy)); OnDrawOutline(g, scaleSize, gp); gp.Dispose(); }
public Region GetFigure() { var path = new GraphicsPath(); path.AddPolygon(points); var region = new Region(path); path.Dispose(); return region; }
public static void FillTopRoundRectangle(Graphics g, Brush brush, Rectangle rectangle, float radius) { float size = radius * 2f; GraphicsPath gp = new GraphicsPath(); gp.AddArc(rectangle.X, rectangle.Y, size, size, 180, 90); gp.AddArc(rectangle.X + rectangle.Width - size, rectangle.Y, size, size, 270, 90); gp.AddLine(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height, rectangle.X, rectangle.Y + rectangle.Height); gp.CloseFigure(); g.FillPath(brush, gp); gp.Dispose(); }
public static void DrawRoundRectangle(Graphics g, Pen pen, Rectangle rectangle, float radius) { float size = radius * 2f; GraphicsPath gp = new GraphicsPath(); gp.AddArc(rectangle.X, rectangle.Y, size, size, 180, 90); gp.AddArc(rectangle.X + rectangle.Width - size, rectangle.Y, size, size, 270, 90); gp.AddArc(rectangle.X + rectangle.Width - size, rectangle.Y + rectangle.Height - size, size, size, 0, 90); gp.AddArc(rectangle.X, rectangle.Y + rectangle.Height - size, size, size, 90, 90); gp.CloseFigure(); g.DrawPath(pen, gp); gp.Dispose(); }
/// <summary> /// This routine draws the animated bomb /// using two toggling graphics paths /// giving the effect of a spinning bomb /// </summary> /// <param name="g"></param> public override void Draw(Graphics g) { UpdateBounds(); Matrix m = new Matrix(); m.Translate(MovingBounds.Left, MovingBounds.Top); // g.FillRectangle(Brushes.White , MovingBounds); if (_invert) { bombInTransformed = (GraphicsPath)bombIn.Clone(); bombInTransformed.Transform(m); g.DrawPath(BombPen, bombInTransformed); bombInTransformed.Dispose(); } else { bombOutTransformed = (GraphicsPath)bombOut.Clone(); bombOutTransformed.Transform(m); g.DrawPath(BombPen, bombOutTransformed); bombOutTransformed.Dispose(); } /* Matrix flipMatrix = new Matrix(); flipMatrix.Scale(-1.0f, 1.0f); m.Translate(MovingBounds.Left, MovingBounds.Top); if (_invert) { m.Scale(-1, 1); // flip around the y axis } // g.FillRectangle(Brushes.White , MovingBounds); bombInTransformed = (GraphicsPath)bombIn.Clone(); bombInTransformed.Transform(m); g.DrawPath(BombPen, bombInTransformed); bombInTransformed.Dispose(); */ _invert = !_invert; // g.DrawPolygon(Pens.White, new PointF[]{new PointF(Position.X, Position.Y), // new PointF(Position.X + width, Position.Y + seg), // new PointF(Position.X, Position.Y + seg*2), // new PointF(Position.X + 3, Position.Y + seg*3)}); Position.Y += TheBombInterval; }
private void DrawRoundRect(Graphics g, Brush p, float X, float Y, float width, float height, float radius) { GraphicsPath gp = new GraphicsPath(); //Upper-right arc: gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); //Lower-right arc: gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); //Lower-left arc: gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); //Upper-left arc: gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90); gp.CloseFigure(); g.FillPath(p, gp); gp.Dispose(); }
public static void FillRoundedRectangle(Graphics g, Brush b, float X, float Y, float width, float height, float radius) { GraphicsPath gp = new GraphicsPath(); gp.AddLine(X + radius, Y, X + width - (radius * 2), Y); gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2)); gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height); gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); gp.AddLine(X, Y + height - (radius * 2), X, Y + radius); gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90); gp.CloseFigure(); g.FillPath(b, gp); gp.Dispose(); }
public void RoundedCornerRectangle(Graphics gfxObj, Pen penObj, float X, float Y, float RectWidth, float RectHeight, float CornerRadius) { GraphicsPath gfxPath = new GraphicsPath(); gfxPath.AddLine(X + CornerRadius, Y, X + RectWidth - (CornerRadius * 2), Y); gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y, CornerRadius * 2, CornerRadius * 2, 270, 90); gfxPath.AddLine(X + RectWidth, Y + CornerRadius, X + RectWidth, Y + RectHeight - (CornerRadius * 2)); gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 0, 90); gfxPath.AddLine(X + RectWidth - (CornerRadius * 2), Y + RectHeight, X + CornerRadius, Y + RectHeight); gfxPath.AddArc(X, Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 90, 90); gfxPath.AddLine(X, Y + RectHeight - (CornerRadius * 2), X, Y + CornerRadius); gfxPath.AddArc(X, Y, CornerRadius * 2, CornerRadius * 2, 180, 90); gfxPath.CloseFigure(); gfxObj.DrawPath(penObj, gfxPath); gfxPath.Dispose(); }
public static void Draw(Graphics graphics, Pen border, Brush background, RectangleF rectangle, float cornerRadius) { Debug.Assert(rectangle.Height >= (2 * cornerRadius)); GraphicsPath rectanglePath = new GraphicsPath(); float halfBorder = border.Width * 0.5f; rectangle.Offset(halfBorder, halfBorder); rectangle.Height -= border.Width; rectangle.Width -= border.Width; if (rectangle.Height > (2 * cornerRadius)) { // Top left rectanglePath.AddArc(rectangle.Left, rectangle.Top, cornerRadius * 2, cornerRadius * 2, 180, 90); // Top right rectanglePath.AddArc(rectangle.Right - (2 * cornerRadius), rectangle.Top, cornerRadius * 2, cornerRadius * 2, 270, 90); // Bottom right rectanglePath.AddArc(rectangle.Right - (2 * cornerRadius), rectangle.Bottom - (2 * cornerRadius), cornerRadius * 2, cornerRadius * 2, 0, 90); // Bottom left rectanglePath.AddArc(rectangle.Left, rectangle.Bottom - (2 * cornerRadius), cornerRadius * 2, cornerRadius * 2, 90, 90); } else { // Left rectanglePath.AddArc(rectangle.Left, rectangle.Top, cornerRadius * 2, cornerRadius * 2, 90, 180); // Right rectanglePath.AddArc(rectangle.Right - (2 * cornerRadius), rectangle.Top, cornerRadius * 2, cornerRadius * 2, 270, 180); } rectanglePath.CloseFigure(); graphics.FillPath(background, rectanglePath); graphics.DrawPath(border, rectanglePath); rectanglePath.Dispose(); }
/// <summary> /// Draws a radial gradient in the label /// </summary> /// <param name="e">paint arguments</param> protected override void OnPaint(PaintEventArgs e) { GraphicsPath path = new GraphicsPath(); path.AddEllipse(this.ClientRectangle); PathGradientBrush brush = new PathGradientBrush(path); brush.CenterPoint = new PointF(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2); brush.CenterColor = this.StartColor; brush.SurroundColors = new Color[] { this.EndColor }; e.Graphics.FillPath(brush, path); brush.Dispose(); path.Dispose(); }
public static void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius) { GraphicsPath path = new GraphicsPath(); path.AddLine(X + radius, Y, X + width - (radius * 2), Y); path.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); path.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2)); path.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); path.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height); path.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); path.AddLine(X, Y + height - (radius * 2), X, Y + radius); path.AddArc(X, Y, radius * 2, radius * 2, 180, 90); path.CloseFigure(); g.DrawPath(p, path); path.Dispose(); }
public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius) { GraphicsPath gp = new GraphicsPath(); gp.AddLine(X + radius, Y, X + width - (radius * 2), Y); gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2)); gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height); gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); gp.AddLine(X, Y + height - (radius * 2), X, Y + radius); gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90); gp.CloseFigure(); Brush Brush = new System.Drawing.SolidBrush(ColorTranslator.FromHtml("#66BD2B")); g.FillPath(Brush, gp); gp.Dispose(); }
public static void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius) { g.SmoothingMode = SmoothingMode.AntiAlias; GraphicsPath gp = new GraphicsPath(); gp.AddLine(X + radius, Y, X + width - (radius * 2), Y); gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2)); gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height); gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); gp.AddLine(X, Y + height - (radius * 2), X, Y + radius); gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90); gp.CloseFigure(); g.DrawPath(p, gp); gp.Dispose(); }
public static void DrawRoundedRectangle(Graphics g, Brush brush, Pen pen, Rectangle rect, float radiusx, float radiusy) { float rx = Math.Min(radiusx * 2, rect.Width); float ry = Math.Min(radiusy * 2, rect.Height); GraphicsPath gp = new GraphicsPath(); gp.AddArc(rect.X, rect.Y, rx, ry, 180, 90); gp.AddArc(rect.X + rect.Width - rx, rect.Y, rx, ry, 270, 90); gp.AddArc(rect.X + rect.Width - rx, rect.Y + rect.Height - ry, rx, ry, 0, 90); gp.AddArc(rect.X, rect.Y + rect.Height - ry, rx, ry, 90, 90); gp.CloseFigure(); if (brush != null) g.FillPath(brush, gp); if (pen != null) g.DrawPath(pen, gp); gp.Dispose(); }
protected override void OnLoad(EventArgs e) { GraphicsPath path = new GraphicsPath(); Rectangle rect = this.ClientRectangle; Size size = new Size(20, 20); path.AddArc(0, 0, size.Width, size.Height, 180, 90); path.AddArc(rect.Width - size.Width, 0, size.Width, size.Height, 270, 90); path.AddArc(rect.Width - size.Width, rect.Height - size.Height, size.Width, size.Height, 0, 90); path.AddArc(0, rect.Height - size.Height, size.Width, size.Height, 90, 90); path.CloseFigure(); this.Region = new Region(path); //创建圆角矩形区域 path.Dispose(); Areo.AreoParams parameter = new Areo.AreoParams(); parameter.Flags = Areo.AreoParams.ENABLE; parameter.Enable = true; parameter.AreoRegion = IntPtr.Zero; Areo.AreoWindow(this.Handle, parameter); //将整个窗体背景设置成Areo效果 }
/// <summary>This method will paint the group title.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintGroupText(System.Drawing.Graphics g) { //Check if string has something------------- if (this.GroupTitle == string.Empty) { return; } //------------------------------------------ //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ SizeF stringSize = g.MeasureString(this.GroupTitle, this.Font); Size stringSize2 = stringSize.ToSize(); if (this.GroupImage != null) { stringSize2.Width += 18; } //int ArcWidth = this.RoundCorners; //int ArcHeight = this.RoundCorners; int arcWidth = this.HeaderRoundCorners; int arcHeight = this.HeaderRoundCorners; //int intX1 = 0; //int intX2 = 0; //int ArcX1 = 10; //int ArcX2 = (StringSize2.Width + 34) - (ArcWidth + 1); int ArcX1 = 20; int ArcX2 = (stringSize2.Width + 34) - (arcWidth + 1); int ArcY1 = 2; int ArcY2 = 22 - (arcHeight + 1); //Add by WZW 2008-12-16 增加GroupTitleBox对齐方式 ===Start int intMidX = this.Size.Width / 2; int intMidX1 = (ArcX2 - ArcX1) / 2; int CustomStringWidth = (this.GroupImage != null) ? 44 : 28; _vXTrans = intMidX - intMidX1 - ArcX1;//X坐标平移距离 int intTitleTextSpace = CustomStringWidth - ArcX1; //中间对齐 if (this._vGroupBoxAlignMode == GroupBoxAlignMode.Center) { ArcX1 = intMidX - intMidX1; ArcX2 = intMidX + intMidX1; CustomStringWidth = ArcX1 + intTitleTextSpace; } else if (this._vGroupBoxAlignMode == GroupBoxAlignMode.Right) { ArcX1 = intMidX + intMidX - ArcX2; ArcX2 = ArcX1 + intMidX1 + intMidX1; CustomStringWidth = ArcX1 + intTitleTextSpace; } //标题与左边线距离 ArcX1 -= this.TitleLeftSpace; ArcX2 -= this.TitleLeftSpace; //Add by WZW 2008-12-16 增加GroupTitleBox对齐方式 ===End System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = (this.PaintGroupBox) ? new SolidBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush TextColorBrush = new SolidBrush(this.ForeColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), arcWidth, arcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), arcWidth, arcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), arcWidth, arcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), arcWidth, arcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(new SolidBrush(Color.Transparent), ShadowPath); //g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Edit BY WZW 2008-12-16 //是否显示标题边框------ if (this._vShowTileRectangle) { //创建title边框路径 path.AddArc(ArcX1, ArcY1, arcWidth, arcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left path.AddArc(ArcX2, ArcY1, arcWidth, arcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right path.AddArc(ArcX2, ArcY2, arcWidth, arcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, arcWidth, arcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left path.CloseAllFigures(); //画Title边框 g.DrawPath(BorderPen, path); } //----------------------------------- //Check if Gradient Mode is enabled-- if (this.PaintGroupBox) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } } //----------------------------------- //绘制title文字------------------------- //int CustomStringWidth = (this.GroupImage != null) ? 44 : 28; //if(this.GroupImage!=null) //{ // CustomStringWidth += 2; //} //g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth, 5); // g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth-this.TitleLeftSpace-2, 5); g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth - this.TitleLeftSpace, 5); //----------------------------------- //Draw GroupImage if there is one---- if (this.GroupImage != null) { //因增加了标题对齐功能,需修改X坐标值 By WZW 2008-12-17 g.DrawImage(this.GroupImage, ArcX1 + 5, 4, 16, 16); } //释放资源------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (TextColorBrush != null) { TextColorBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } }
/// <summary>This method will paint the control.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintBack(System.Drawing.Graphics g) { //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ int ArcWidth = this.RoundCorners * 2; int ArcHeight = this.RoundCorners * 2; int ArcX1 = 0; int ArcX2 = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1); int ArcY1 = 10; int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1); int intXEnd = 20; if (GroupBoxAlignMode.Center == this._vGroupBoxAlignMode) { intXEnd += _vXTrans; } else if (GroupBoxAlignMode.Right == this._vGroupBoxAlignMode) { intXEnd += _vXTrans * 2; } int intTextLength = g.MeasureString(this.GroupTitle, this.Font).ToSize().Width + 34 - (ArcWidth + 1) - 20; int intXStart = intXEnd + intTextLength + ArcWidth; int X1 = intXEnd; int X2 = intXStart; if (this.GroupImage != null) { if (this.ShowTileRectangle) { X2 += 18; } else { X2 += 10; } } else { if (!this.ShowTileRectangle) { X1 += 8 - this.TextLineSpace; X2 -= 8 - this.TextLineSpace; } } X1 -= this.TitleLeftSpace; X2 -= this.TitleLeftSpace; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Edit BY WZW 2008-12-16 //Create Rounded Rectangle Path------ //path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left //path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right //path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right //path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left //path.CloseAllFigures(); //g.DrawPath(BorderPen, path); //----------------------------------- //g.DrawArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); //绘制标题外边框----------------------- //左上角 g.DrawArc(BorderPen, ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); //左上至右上分两段画线,两段之间为标题外框 BorderPen = new Pen(BorderBrush, this.BorderThickness); g.DrawLine(BorderPen, new Point(ArcX1 + this.RoundCorners, ArcY1), new Point(X1, ArcY1)); //左边一段直线 BorderPen = new Pen(BorderBrush, this.BorderThickness); g.DrawLine(BorderPen, new Point(X2, ArcY1), new Point(ArcX2 + this.RoundCorners, ArcY1)); //右边一段直线 //右上角 g.DrawArc(BorderPen, ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); if (!_vBorderTopOnly) { //右上至右下 g.DrawLine(BorderPen, new Point(ArcX2 + ArcWidth, ArcY1 + this.RoundCorners), new Point(ArcX2 + ArcHeight, ArcY2 + this.RoundCorners)); //右下角 g.DrawArc(BorderPen, ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //右下至左下 g.DrawLine(BorderPen, new Point(ArcX2 + this.RoundCorners, ArcY2 + ArcWidth), new Point(ArcX1 + this.RoundCorners, ArcY2 + ArcWidth)); //左下角 g.DrawArc(BorderPen, ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //左下只左上 g.DrawLine(BorderPen, new Point(ArcX1, ArcY2 + this.RoundCorners), new Point(ArcX1, ArcY1 + this.RoundCorners)); //g.DrawPath(BorderPen, path); } //Check if Gradient Mode is enabled-- if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } //----------------------------------- //Delete BY WZW //Paint Borded----------------------- //g.DrawPath(BorderPen, path); //g.DrawLine(SystemPens.Control, 10, 10, 100, 10); //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }
private static void CalculateLabelAroundOnLineString(SharpMap.Geometries.LineString line, ref BaseLabel label, Map map, System.Drawing.Graphics g, System.Drawing.SizeF textSize) { IList <SharpMap.Geometries.Point> sPoints = line.Vertices; // only get point in enverlop of map Collection <System.Drawing.PointF> colPoint = new Collection <System.Drawing.PointF>(); bool bCheckStarted = false; for (int j = 0; j < sPoints.Count; j++) { if (map.Envelope.Grow(map.PixelSize * 10).Contains(sPoints[j])) { //points[j] = map.WorldToImage(sPoints[j]); colPoint.Add(map.WorldToImage(sPoints[j])); bCheckStarted = true; } else if (bCheckStarted == true) { // fix bug curved line out of map in center segment of line break; } } if (colPoint.Count > 1) { label.TextOnPathLabel = new SharpMap.Rendering.TextOnPath(); switch (label.Style.HorizontalAlignment) { case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left: label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left; break; case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right: label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right; break; case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center: label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center; break; default: label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center; break; } switch (label.Style.VerticalAlignment) { case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom: label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.UnderPath; break; case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Top: label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.OverPath; break; case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Middle: label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath; break; default: label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath; break; } int idxStartPath = 0; int numberPoint = colPoint.Count; // start Optimzes Path points int step = 100; if (colPoint.Count >= step * 2) { numberPoint = step * 2;; switch (label.Style.HorizontalAlignment) { case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left: //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left; idxStartPath = 0; break; case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right: //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right; idxStartPath = colPoint.Count - step; break; case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center: //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center; idxStartPath = (int)colPoint.Count / 2 - step; break; default: //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center; idxStartPath = (int)colPoint.Count / 2 - step; break; } } // end optimize path point System.Drawing.PointF[] points = new System.Drawing.PointF[numberPoint]; int count = 0; if (colPoint[0].X <= colPoint[colPoint.Count - 1].X) { for (int l = idxStartPath; l < numberPoint + idxStartPath; l++) { points[count] = colPoint[l]; count++; } } else { //reverse the path for (int k = numberPoint - 1 + idxStartPath; k >= idxStartPath; k--) { points[count] = colPoint[k]; count++; } } //get text size in page units ie pixels float textheight = label.Style.Font.Size; switch (label.Style.Font.Unit) { case System.Drawing.GraphicsUnit.Display: textheight = textheight * g.DpiY / 75; break; case System.Drawing.GraphicsUnit.Document: textheight = textheight * g.DpiY / 300; break; case System.Drawing.GraphicsUnit.Inch: textheight = textheight * g.DpiY; break; case System.Drawing.GraphicsUnit.Millimeter: textheight = (float)(textheight / 25.4 * g.DpiY); break; case System.Drawing.GraphicsUnit.Pixel: //do nothing break; case System.Drawing.GraphicsUnit.Point: textheight = textheight * g.DpiY / 72; break; } System.Drawing.Font topFont = new System.Drawing.Font(label.Style.Font.FontFamily, textheight, label.Style.Font.Style); // System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddLines(points); label.TextOnPathLabel.PathColorTop = System.Drawing.Color.Transparent; label.TextOnPathLabel.Text = label.Text; label.TextOnPathLabel.LetterSpacePercentage = 90; label.TextOnPathLabel.FillColorTop = new System.Drawing.SolidBrush(label.Style.ForeColor); label.TextOnPathLabel.Font = topFont; label.TextOnPathLabel.PathDataTop = path.PathData; label.TextOnPathLabel.Graphics = g; //label.TextOnPathLabel.ShowPath=true; //label.TextOnPathLabel.PathColorTop = System.Drawing.Color.YellowGreen; if (label.Style.Halo != null) { label.TextOnPathLabel.ColorHalo = label.Style.Halo; } else { label.TextOnPathLabel.ColorHalo = null;// new System.Drawing.Pen(label.Style.ForeColor, (float)0.5); } path.Dispose(); // MeasureString to get region label.TextOnPathLabel.MeasureString = true; label.TextOnPathLabel.DrawTextOnPath(); label.TextOnPathLabel.MeasureString = false; // Get Region label for CollissionDetection here. System.Drawing.Drawing2D.GraphicsPath pathRegion = new System.Drawing.Drawing2D.GraphicsPath(); if (label.TextOnPathLabel.RegionList.Count > 0) { //int idxCenter = (int)label.TextOnPathLabel.PointsText.Count / 2; //System.Drawing.Drawing2D.Matrix rotationMatrix = g.Transform.Clone();// new Matrix(); //rotationMatrix.RotateAt(label.TextOnPathLabel.Angles[idxCenter], label.TextOnPathLabel.PointsText[idxCenter]); //if (label.TextOnPathLabel.PointsTextUp.Count > 0) //{ // for (int up = label.TextOnPathLabel.PointsTextUp.Count - 1; up >= 0; up--) // { // label.TextOnPathLabel.PointsText.Add(label.TextOnPathLabel.PointsTextUp[up]); // } //} pathRegion.AddRectangles(label.TextOnPathLabel.RegionList.ToArray()); // get box for detect colission here label.Box = new LabelBox(pathRegion.GetBounds()); //g.FillRectangle(System.Drawing.Brushes.YellowGreen, label.Box); } pathRegion.Dispose(); } }
/// <summary> /// 文字列を描画したテクスチャを返す(メイン処理) /// </summary> /// <param name="rectDrawn">描画された領域</param> /// <param name="ptOrigin">描画文字列</param> /// <param name="drawstr">描画文字列</param> /// <param name="drawmode">描画モード</param> /// <param name="fontColor">描画色</param> /// <param name="edgeColor">縁取色</param> /// <param name="gradationTopColor">グラデーション 上側の色</param> /// <param name="gradationBottomColor">グラデーション 下側の色</param> /// <returns>描画済テクスチャ</returns> protected Bitmap DrawPrivateFont_V(string drawstr, Color fontColor, Color edgeColor, bool bVertical) { if (this._fontfamily == null || drawstr == null || drawstr == "") { // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。 // それは非常に面倒なので、最小限のbitmapを返してしまう。 // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。 if (drawstr != "") { Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。"); } _rectStrings = new Rectangle(0, 0, 0, 0); _ptOrigin = new Point(0, 0); return(new Bitmap(1, 1)); } //StreamWriter stream = stream = new StreamWriter("Test.txt", false); //try //{ // stream = new StreamWriter("Test.txt", false); //} //catch (Exception ex) //{ // stream.Close(); // stream = new StreamWriter("Test.txt", false); //} string[] strName = new string[drawstr.Length]; for (int i = 0; i < drawstr.Length; i++) { strName[i] = drawstr.Substring(i, 1); } #region [ キャンバスの大きさ予測 ] //大きさを計算していく。 int nHeight = 0; for (int i = 0; i < strName.Length; i++) { Size strSize = System.Windows.Forms.TextRenderer.MeasureText(strName[i], this._font, new Size(int.MaxValue, int.MaxValue), System.Windows.Forms.TextFormatFlags.NoPrefix | System.Windows.Forms.TextFormatFlags.NoPadding); //stringformatは最初にやっていてもいいだろう。 StringFormat sFormat = new StringFormat(); sFormat.LineAlignment = StringAlignment.Center; // 画面下部(垂直方向位置) sFormat.Alignment = StringAlignment.Center; // 画面中央(水平方向位置) //できるだけ正確な値を計算しておきたい...! Bitmap bmpDummy = new Bitmap(150, 150); //とりあえず150 Graphics gCal = Graphics.FromImage(bmpDummy); Rectangle rect正確なサイズ = this.MeasureStringPrecisely(gCal, strName[i], this._font, strSize, sFormat); int n余白サイズ = strSize.Height - rect正確なサイズ.Height; Rectangle rect = new Rectangle(0, -n余白サイズ + 2, 36, (strSize.Height + 12)); if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~" || strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "「" || strName[i] == "」" || strName[i] == "[" || strName[i] == "]") { nHeight += (rect正確なサイズ.Width) + 3; } else if (strName[i] == "_") { nHeight += (rect正確なサイズ.Height) + 6; } else if (strName[i] == " ") { nHeight += (12); } else { nHeight += (rect正確なサイズ.Height) + 6; } //念のため解放 bmpDummy.Dispose(); gCal.Dispose(); //stream.WriteLine( "文字の大きさ{0},大きさ合計{1}", ( rect正確なサイズ.Height ) + 6, nHeight ); } #endregion Bitmap bmpCambus = new Bitmap(36, nHeight); Graphics Gcambus = Graphics.FromImage(bmpCambus); //キャンバス作成→1文字ずつ作成してキャンバスに描画という形がよさそうかな? int nNowPos = 0; int nAdded = 0; if (this._pt < 18) { nAdded = nAdded - 2; } for (int i = 0; i < strName.Length; i++) { Size strSize = System.Windows.Forms.TextRenderer.MeasureText(strName[i], this._font, new Size(int.MaxValue, int.MaxValue), System.Windows.Forms.TextFormatFlags.NoPrefix | System.Windows.Forms.TextFormatFlags.NoPadding); //stringformatは最初にやっていてもいいだろう。 StringFormat sFormat = new StringFormat(); sFormat.LineAlignment = StringAlignment.Center; // 画面下部(垂直方向位置) sFormat.Alignment = StringAlignment.Near; // 画面中央(水平方向位置) //できるだけ正確な値を計算しておきたい...! Bitmap bmpDummy = new Bitmap(150, 150); //とりあえず150 Graphics gCal = Graphics.FromImage(bmpDummy); Rectangle rect正確なサイズ = this.MeasureStringPrecisely(gCal, strName[i], this._font, strSize, sFormat); int n余白サイズ = strSize.Height - rect正確なサイズ.Height; //Bitmap bmpV = new Bitmap( 36, ( strSize.Height + 12 ) - 6 ); Bitmap bmpV = new Bitmap((rect正確なサイズ.Width + 8) + nAdded, (rect正確なサイズ.Height) + 8); bmpV.MakeTransparent(); Graphics gV = Graphics.FromImage(bmpV); gV.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Rectangle rect = new Rectangle(-3 - nAdded, -rect正確なサイズ.Y - 2, (strSize.Width + 12), (strSize.Height + 12)); //Rectangle rect = new Rectangle( 0, -rect正確なサイズ.Y - 2, 36, rect正確なサイズ.Height + 10); // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する // (これをしないと、単位が違うために、小さめに描画されてしまう) float sizeInPixels = _font.SizeInPoints * gV.DpiY / 72; // 1 inch = 72 points System.Drawing.Drawing2D.GraphicsPath gpV = new System.Drawing.Drawing2D.GraphicsPath(); gpV.AddString(strName[i], this._fontfamily, (int)this._font.Style, sizeInPixels, rect, sFormat); // 縁取りを描画する Pen pV = new Pen(edgeColor, 6); pV.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; gV.DrawPath(pV, gpV); // 塗りつぶす Brush brV; { brV = new SolidBrush(fontColor); } gV.FillPath(brV, gpV); if (brV != null) { brV.Dispose(); } brV = null; if (pV != null) { pV.Dispose(); } pV = null; if (gpV != null) { gpV.Dispose(); } gpV = null; int n補正 = 0; int nY補正 = 0; if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~") { bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone); n補正 = 2; if (this._pt < 20) { n補正 = 0; } //nNowPos = nNowPos - 2; } else if (strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "[" || strName[i] == "]" || strName[i] == "」") { bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone); n補正 = 2; if (this._pt < 20) { n補正 = 0; //nNowPos = nNowPos - 4; } } else if (strName[i] == "「") { bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone); n補正 = 2; if (this._pt < 20) { n補正 = 2; //nNowPos = nNowPos; } } //else if( strName[ i ] == "_" ) // nNowPos = nNowPos + 20; else if (strName[i] == " ") { nNowPos = nNowPos + 10; } //bmpV.Save( "String" + i.ToString() + ".png" ); if (i == 0) { nNowPos = 0; Gcambus.DrawImage(bmpV, (16 - (bmpV.Size.Width / 2)) + n補正, 0); } else { Gcambus.DrawImage(bmpV, (16 - (bmpV.Size.Width / 2)) + n補正, nNowPos); } nNowPos += bmpV.Size.Height - 3; if (bmpV != null) { bmpV.Dispose(); } bmpV = null; if (gCal != null) { gCal.Dispose(); } gCal = null; //bmpCambus.Save( "test.png" ); //if( this._pt < 20 ) // bmpCambus.Save( "test_S.png" ); _rectStrings = new Rectangle(0, 0, strSize.Width, strSize.Height); _ptOrigin = new Point(6 * 2, 6 * 2); //stream.WriteLine( "黒無しサイズ{0},余白{1},黒あり予測サイズ{2},ポ↑ジ↓{3}",rect正確なサイズ.Height, n余白サイズ, rect正確なサイズ.Height + 8, nNowPos ); } //stream.Close(); if (Gcambus != null) { Gcambus.Dispose(); } //return bmp; return(bmpCambus); }
private void DrawBackground(System.Drawing.Graphics g) { //Graphics g = bg.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; int ArcWidth = this.C_RoundCorners * 2; int ArcHeight = this.C_RoundCorners * 2; int ArcX1 = 0; int ArcX2 = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1); int ArcY1 = 0; int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(_colorFrame); //this.BorderColor System.Drawing.Pen BorderPen = new Pen(BorderBrush, _frameBorder); //this.BorderThickness System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //画出阴影效果 if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, SweepAngle); //顶端的左角 ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, SweepAngle); //顶端右角 ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, SweepAngle); //底部右角 ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, SweepAngle); //底部左角 ShadowPath.CloseAllFigures(); g.FillPath(ShadowBrush, ShadowPath); } //画出图形 path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle); path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle); path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle); path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle); path.CloseAllFigures(); if (this.C_BackgroundGradientMode == DutBoxGradientMode.None) { g.FillPath(BackgroundBrush, path); } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); g.FillPath(BackgroundGradientBrush, path); } //画对号 if (IsActivedDut && ManualChecked) { //g.DrawLine(BorderPen, 10, 10, 20, 20); int x = Width - 30; int y = 12; /* * x--; y++; * g.DrawLine(pen, x, y, x, y + 4); * x--; y++; * g.DrawLine(pen, x, y, x, y + 2); * x--; y++; * x = Width - 30; * y = 12; * */ for (int i = 0; i < 6; i++) { g.DrawLine(CheckedPen, x, y, x, y + 6); x++; y++; } for (int i = 0; i < 12; i++) { g.DrawLine(CheckedPen, x, y, x, y + 6); x++; y--; } /* * g.DrawLine(pen, x, y + 2, x, y + 6); * x++; y++; * g.DrawLine(pen, x, y + 2, x, y + 4); * x++; y++; * */ } //画边框 if (IsActivedDut) { g.DrawPath(BorderPen, path); } else { System.Drawing.Brush defaultBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen defaultPen = new Pen(defaultBrush, this.BorderThickness); g.DrawPath(defaultPen, path); } //销毁Graphic 对象 if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderPen.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } }
/// <summary> /// 文字列を描画したテクスチャを返す(メイン処理) /// </summary> /// <param name="rectDrawn">描画された領域</param> /// <param name="ptOrigin">描画文字列</param> /// <param name="drawstr">描画文字列</param> /// <param name="drawmode">描画モード</param> /// <param name="fontColor">描画色</param> /// <param name="edgeColor">縁取色</param> /// <param name="gradationTopColor">グラデーション 上側の色</param> /// <param name="gradationBottomColor">グラデーション 下側の色</param> /// <returns>描画済テクスチャ</returns> protected Bitmap DrawPrivateFont_V(string drawstr, Color fontColor, Color edgeColor, bool bVertical) { if (this._fontfamily == null || drawstr == null || drawstr == "") { // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。 // それは非常に面倒なので、最小限のbitmapを返してしまう。 // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。 if (drawstr != "") { Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。"); } _rectStrings = new Rectangle(0, 0, 0, 0); _ptOrigin = new Point(0, 0); return(new Bitmap(1, 1)); } //StreamWriter stream = stream = new StreamWriter("Test.txt", false); //try //{ // stream = new StreamWriter("Test.txt", false); //} //catch (Exception ex) //{ // stream.Close(); // stream = new StreamWriter("Test.txt", false); //} string[] strName = new string[drawstr.Length]; for (int i = 0; i < drawstr.Length; i++) { strName[i] = drawstr.Substring(i, 1); } #region [ キャンバスの大きさ予測 ] //大きさを計算していく。 int nHeight = 0; for (int i = 0; i < strName.Length; i++) { Size strSize = System.Windows.Forms.TextRenderer.MeasureText(strName[i], this._font, new Size(int.MaxValue, int.MaxValue), System.Windows.Forms.TextFormatFlags.NoPrefix | System.Windows.Forms.TextFormatFlags.NoPadding); //stringformatは最初にやっていてもいいだろう。 StringFormat sFormat = new StringFormat(); sFormat.LineAlignment = StringAlignment.Center; // 画面下部(垂直方向位置) sFormat.Alignment = StringAlignment.Center; // 画面中央(水平方向位置) //できるだけ正確な値を計算しておきたい...! Bitmap bmpDummy = new Bitmap(150, 150); //とりあえず150 Graphics gCal = Graphics.FromImage(bmpDummy); Rectangle rect正確なサイズ = this.MeasureStringPrecisely(gCal, strName[i], this._font, strSize, sFormat); int n余白サイズ = strSize.Height - rect正確なサイズ.Height; Rectangle rect = new Rectangle(0, -n余白サイズ + 2, 46, (strSize.Height + 16)); if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~" || strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "「" || strName[i] == "」" || strName[i] == "[" || strName[i] == "]") { nHeight += (rect正確なサイズ.Width) + 4; } else if (strName[i] == "_") { nHeight += (rect正確なサイズ.Height) + 6; } else if (strName[i] == " ") { nHeight += (12); } else { nHeight += (rect正確なサイズ.Height) + 10; } //念のため解放 bmpDummy.Dispose(); gCal.Dispose(); //stream.WriteLine( "文字の大きさ{0},大きさ合計{1}", ( rect正確なサイズ.Height ) + 6, nHeight ); } #endregion Bitmap bmpCambus = new Bitmap(46, nHeight); Graphics Gcambus = Graphics.FromImage(bmpCambus); //キャンバス作成→1文字ずつ作成してキャンバスに描画という形がよさそうかな? int nNowPos = 0; int nAdded = 0; int nEdge補正X = 0; int nEdge補正Y = 0; if (this._pt < 18) { nAdded = nAdded - 2; } for (int i = 0; i < strName.Length; i++) { Size strSize = System.Windows.Forms.TextRenderer.MeasureText(strName[i], this._font, new Size(int.MaxValue, int.MaxValue), System.Windows.Forms.TextFormatFlags.NoPrefix | System.Windows.Forms.TextFormatFlags.NoPadding); //stringformatは最初にやっていてもいいだろう。 StringFormat sFormat = new StringFormat(); sFormat.LineAlignment = StringAlignment.Center; // 画面下部(垂直方向位置) sFormat.Alignment = StringAlignment.Near; // 画面中央(水平方向位置) //できるだけ正確な値を計算しておきたい...! Bitmap bmpDummy = new Bitmap(150, 150); //とりあえず150 Graphics gCal = Graphics.FromImage(bmpDummy); Rectangle rect正確なサイズ = this.MeasureStringPrecisely(gCal, strName[i], this._font, strSize, sFormat); int n余白サイズ = strSize.Height - rect正確なサイズ.Height; //Bitmap bmpV = new Bitmap( 36, ( strSize.Height + 12 ) - 6 ); Bitmap bmpV = new Bitmap((rect正確なサイズ.Width + 12) + nAdded, (rect正確なサイズ.Height) + 12); bmpV.MakeTransparent(); Graphics gV = Graphics.FromImage(bmpV); gV.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; if (strName[i].In(TJAPlayer3.Skin.SongSelect_CorrectionX_Chara)) { nEdge補正X = TJAPlayer3.Skin.SongSelect_CorrectionX_Chara_Value; } else { nEdge補正X = 0; } if (strName[i].In(TJAPlayer3.Skin.SongSelect_CorrectionY_Chara)) { nEdge補正Y = TJAPlayer3.Skin.SongSelect_CorrectionY_Chara_Value; } else { nEdge補正Y = 0; } //X座標、Y座標それぞれについて、SkinConfig内でズレを直したい文字を , で区切って列挙して、 //補正値を記入することで、特定のそれらの文字について一括で座標をずらす。 //現時点では補正値をX,Y各座標について1個ずつしか取れない(複数対1)ので、 //文字を列挙して、同じ数だけそれぞれの文字の補正値を記入できるような枠組をつくりたい。(20181205 rhimm) Rectangle rect = new Rectangle(-3 - nAdded + (nEdge補正X * _pt / 100), -rect正確なサイズ.Y - 2 + (nEdge補正Y * _pt / 100), (strSize.Width + 12), (strSize.Height + 12)); //Rectangle rect = new Rectangle( 0, -rect正確なサイズ.Y - 2, 36, rect正確なサイズ.Height + 10); // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する // (これをしないと、単位が違うために、小さめに描画されてしまう) float sizeInPixels = _font.SizeInPoints * gV.DpiY / 72; // 1 inch = 72 points System.Drawing.Drawing2D.GraphicsPath gpV = new System.Drawing.Drawing2D.GraphicsPath(); gpV.AddString(strName[i], this._fontfamily, (int)this._font.Style, sizeInPixels, rect, sFormat); // 縁取りを描画する //int nEdgePt = (_pt / 3); // 縁取りをフォントサイズ基準に変更 int nEdgePt = (10 * _pt / TJAPlayer3.Skin.Font_Edge_Ratio_Vertical); // SkinConfigにて設定可能に(rhimm) Pen pV = new Pen(edgeColor, nEdgePt); pV.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; gV.DrawPath(pV, gpV); // 塗りつぶす Brush brV; { brV = new SolidBrush(fontColor); } gV.FillPath(brV, gpV); if (brV != null) { brV.Dispose(); } brV = null; if (pV != null) { pV.Dispose(); } pV = null; if (gpV != null) { gpV.Dispose(); } gpV = null; if (gV != null) { gV.Dispose(); } gV = null; int n補正 = 0; int nY補正 = 0; if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~") { bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone); n補正 = 2; if (this._pt < 20) { n補正 = 0; } //nNowPos = nNowPos - 2; } else if (strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "[" || strName[i] == "]" || strName[i] == "」" || strName[i] == ")" || strName[i] == "』") { bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone); n補正 = 2; if (this._pt < 20) { n補正 = 0; //nNowPos = nNowPos - 4; } } else if (strName[i] == "「" || strName[i] == "(" || strName[i] == "『") { bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone); n補正 = 2; if (this._pt < 20) { n補正 = 2; //nNowPos = nNowPos; } } else if (strName[i] == "・") { n補正 = -8; if (this._pt < 20) { n補正 = -8; //nNowPos = nNowPos; } } else if (strName[i] == ".") { n補正 = 8; if (this._pt < 20) { n補正 = 8; //nNowPos = nNowPos; } } else if (strName[i].In(TJAPlayer3.Skin.SongSelect_Rotate_Chara)) { bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone); } //個別の文字に関して、カンマで区切ってSkinConfigに記入したものを回転させる(20181205 rhimm) //else if( strName[ i ] == "_" ) // nNowPos = nNowPos + 20; else if (strName[i] == " ") { nNowPos = nNowPos + 10; } //bmpV.Save( "String" + i.ToString() + ".png" ); if (i == 0) { nNowPos = 4; } Gcambus.DrawImage(bmpV, (bmpCambus.Width / 2) - (bmpV.Width / 2) + n補正, nNowPos + nY補正); nNowPos += bmpV.Size.Height - 6; if (bmpV != null) { bmpV.Dispose(); } bmpV = null; if (gCal != null) { gCal.Dispose(); } gCal = null; //bmpCambus.Save( "test.png" ); //if( this._pt < 20 ) // bmpCambus.Save( "test_S.png" ); _rectStrings = new Rectangle(0, 0, strSize.Width, strSize.Height); _ptOrigin = new Point(6 * 2, 6 * 2); //stream.WriteLine( "黒無しサイズ{0},余白{1},黒あり予測サイズ{2},ポ↑ジ↓{3}",rect正確なサイズ.Height, n余白サイズ, rect正確なサイズ.Height + 8, nNowPos ); } //stream.Close(); if (Gcambus != null) { Gcambus.Dispose(); } //return bmp; return(bmpCambus); }
public void Draw(Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; int ArcWidth = this.C_RoundCorners * 2; int ArcHeight = this.C_RoundCorners * 2; int ArcX1 = Rect.Left; int ArcX2 = (this.ShadowControl) ? (Rect.Left + Rect.Width - (ArcWidth + 1)) - this.ShadowThickness : Rect.Left + Rect.Width - (ArcWidth + 1); int ArcY1 = Rect.Top; int ArcY2 = (this.ShadowControl) ? (Rect.Top + Rect.Height - (ArcHeight + 1)) - this.ShadowThickness : Rect.Top + Rect.Height - (ArcHeight + 1); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(Color.Orange); System.Drawing.Pen BorderPen = new Pen(BorderBrush, 2.0f); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(Color.White); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //画出阴影效果 if (this.ShadowControl) { Color shadowColor = Color.FromArgb(192, this.ShadowColor); //说明:1-(128/255)=1-0.5=0.5 透明度为0.5,即50% ShadowBrush = new SolidBrush(shadowColor); //ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, SweepAngle); //顶端的左角 ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, SweepAngle); //顶端右角 ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, SweepAngle); //底部右角 ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, SweepAngle); //底部左角 ShadowPath.CloseAllFigures(); g.FillPath(ShadowBrush, ShadowPath); } //画出图形 path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle); path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle); path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle); path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle); path.CloseAllFigures(); if (this.C_BackgroundGradientMode == DutBoxGradientMode.None) { BackgroundBrush = new SolidBrush(this.BackgroundGradientColor); g.FillPath(BackgroundBrush, path); } else { Color startColor = Color.FromArgb(192, Color.White); BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(Rect.Left, Rect.Top, Rect.Width, Rect.Height), startColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); g.FillPath(BackgroundGradientBrush, path); } //画边框 if (Focus) { g.DrawPath(BorderPen, path); } else { System.Drawing.Brush defaultBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen defaultPen = new Pen(defaultBrush, this.BorderThickness); g.DrawPath(defaultPen, path); if (defaultBrush != null) { defaultBrush.Dispose(); } if (defaultPen != null) { defaultPen.Dispose(); } } //画内容 ID Font font = new Font("Arial", 14.25F, System.Drawing.FontStyle.Bold); g.DrawString((ID + 1).ToString(), font, Brushes.Black, Rect.Left + 6, Rect.Top + 6); if (Connected) { //画状态 if (!string.IsNullOrEmpty(Status)) { font = new Font("Arial", 11.25F, FontStyle.Bold); g.DrawString(Status, font, Brushes.Black, Rect.Left + 6 + 56, Rect.Top + 6 + 2); } //画进度条 Rectangle bar = new Rectangle(Rect.Left + 6, Rect.Top + 28, Rect.Width - 10, 14); ProgressBar.Rect = bar; g.SmoothingMode = SmoothingMode.Default; ProgressBar.Draw(g); g.SmoothingMode = SmoothingMode.AntiAlias; /* Button but = new Button( ); * but.Text = "打印"; * but.Location = new Point(Rect.Width - 5,14);*/ //画打印图标 20161223 bonnie string haarXmlPath = @"../../打印图标.png"; FileInfo file = new FileInfo(haarXmlPath); string fullName = file.FullName; //画SN if (!string.IsNullOrEmpty(SerialNumber)) { font = new Font("Arial", 10.25F); g.DrawString("SN:" + SerialNumber, font, Brushes.Black, Rect.Left + 6, Rect.Top + 6 + 40); } //画IMEI if (!string.IsNullOrEmpty(IMEI)) { font = new Font("Arial", 10.25F); g.DrawString("IMEI:" + IMEI, font, Brushes.Black, Rect.Left + 6, Rect.Top + 6 + 60); } font = new Font("Arial", 10.25F, FontStyle.Bold); //画time if (ElapsedTime > 0.0f) { g.DrawString((int)ElapsedTime + "/" + (int)EstimateTime, font, Brushes.Black, Rect.Left + 6, Rect.Top + 6 + 80); } //画测试方式 switch (Way) { case TestWay.TW_AUTO: g.DrawString("Auto", font, Brushes.DarkGreen, Rect.Left + 6 + 90, Rect.Top + 6 + 80); break; case TestWay.TW_MANUAL: g.DrawString("Manual", font, Brushes.Red, Rect.Left + 6 + 80, Rect.Top + 6 + 80); break; case TestWay.TW_NONE: break; } //画Model if (!string.IsNullOrEmpty(Model)) { font = new Font("Arial", 10.25F); g.DrawString(Model, font, Brushes.Black, Rect.Left + 6, Rect.Top + 6 + 100); } //画QRCode 48 x 48 if (QRCode != null) { bar = new Rectangle(Rect.Right - 58, Rect.Top + 84, 48, 48); //g.FillRectangle(Brushes.Red, bar); g.SmoothingMode = SmoothingMode.None; g.DrawImageUnscaled(QRCode, bar); g.SmoothingMode = SmoothingMode.AntiAlias; } if (QRCode != null) { FileInfo image_file = new FileInfo($@"./pictures/打印图标.png"); if (image_file.Exists) { PrintIocnImage = Image.FromFile(image_file.FullName); g.SmoothingMode = SmoothingMode.None; g.DrawImage(PrintIocnImage, Rect.Right - 98, Rect.Top + 104); g.SmoothingMode = SmoothingMode.AntiAlias; } } } else // disconnected - TESTING & FAIL { if (Result == ItemResult.IR_TESTING) { StringFormat stringFormat = new StringFormat(); stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Center; stringFormat.FormatFlags = StringFormatFlags.LineLimit; stringFormat.Trimming = StringTrimming.EllipsisCharacter; font = new Font("Arial", 16.25F, FontStyle.Bold); g.DrawString("OFFLINE", font, Brushes.White, Rect, stringFormat); } } //画对号 if (Checked) { //g.DrawLine(BorderPen, 10, 10, 20, 20); int x = Rect.Left + Rect.Width - 30; int y = Rect.Top + 8; Pen pen = new Pen(new SolidBrush(Color.DarkOrange), this.BorderThickness); for (int i = 0; i < 6; i++) { g.DrawLine(pen, x, y, x, y + 6); x++; y++; } for (int i = 0; i < 11; i++) { g.DrawLine(pen, x, y, x, y + 6); x++; y--; } if (pen != null) { pen.Dispose(); } } //销毁Graphic 对象 if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderPen.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } }
/// <summary> /// 文字列を描画したテクスチャを返す(メイン処理) /// </summary> /// <param name="rectDrawn">描画された領域</param> /// <param name="ptOrigin">描画文字列</param> /// <param name="drawstr">描画文字列</param> /// <param name="drawmode">描画モード</param> /// <param name="fontColor">描画色</param> /// <param name="edgeColor">縁取色</param> /// <param name="gradationTopColor">グラデーション 上側の色</param> /// <param name="gradationBottomColor">グラデーション 下側の色</param> /// <returns>描画済テクスチャ</returns> protected Bitmap DrawPrivateFont(string drawstr, DrawMode drawmode, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradationBottomColor) { if (this._fontfamily == null || drawstr == null || drawstr == "") { // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。 // それは非常に面倒なので、最小限のbitmapを返してしまう。 // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。 if (drawstr != "") { Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。"); } _rectStrings = new Rectangle(0, 0, 0, 0); _ptOrigin = new Point(0, 0); return(new Bitmap(1, 1)); } bool bEdge = ((drawmode & DrawMode.Edge) == DrawMode.Edge); bool bGradation = ((drawmode & DrawMode.Gradation) == DrawMode.Gradation); // 縁取りの縁のサイズは、とりあえずフォントの大きさの1/4とする //int nEdgePt = (bEdge)? _pt / 4 : 0; //int nEdgePt = (bEdge) ? (_pt / 3) : 0; // 縁取りが少なすぎるという意見が多かったため変更。 (AioiLight) int nEdgePt = (bEdge) ? (10 * _pt / TJAPlayer3.Skin.Font_Edge_Ratio) : 0; //SkinConfigにて設定可能に(rhimm) // 描画サイズを測定する Size stringSize = System.Windows.Forms.TextRenderer.MeasureText(drawstr, this._font, new Size(int.MaxValue, int.MaxValue), System.Windows.Forms.TextFormatFlags.NoPrefix | System.Windows.Forms.TextFormatFlags.NoPadding ); stringSize.Width += 10; //2015.04.01 kairera0467 ROTTERDAM NATIONの描画サイズがうまくいかんので。 //取得した描画サイズを基に、描画先のbitmapを作成する Bitmap bmp = new Bitmap(stringSize.Width + nEdgePt * 2, stringSize.Height + nEdgePt * 2); bmp.MakeTransparent(); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Far; // 画面下部(垂直方向位置) sf.Alignment = StringAlignment.Center; // 画面中央(水平方向位置) sf.FormatFlags = StringFormatFlags.NoWrap; // どんなに長くて単語の区切りが良くても改行しない (AioiLight) sf.Trimming = StringTrimming.None; // どんなに長くてもトリミングしない (AioiLight) // レイアウト枠 Rectangle r = new Rectangle(0, 0, stringSize.Width + nEdgePt * 2 + (TJAPlayer3.Skin.Text_Correction_X * stringSize.Width / 100), stringSize.Height + nEdgePt * 2 + (TJAPlayer3.Skin.Text_Correction_Y * stringSize.Height / 100)); if (bEdge) // 縁取り有りの描画 { // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する // (これをしないと、単位が違うために、小さめに描画されてしまう) float sizeInPixels = _font.SizeInPoints * g.DpiY / 72; // 1 inch = 72 points System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddString(drawstr, this._fontfamily, (int)this._font.Style, sizeInPixels, r, sf); // 縁取りを描画する Pen p = new Pen(edgeColor, nEdgePt); p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; g.DrawPath(p, gp); // 塗りつぶす Brush br; if (bGradation) { br = new LinearGradientBrush(r, gradationTopColor, gradationBottomColor, LinearGradientMode.Vertical); } else { br = new SolidBrush(fontColor); } g.FillPath(br, gp); if (br != null) { br.Dispose(); } br = null; if (p != null) { p.Dispose(); } p = null; if (gp != null) { gp.Dispose(); } gp = null; } else { // 縁取りなしの描画 System.Windows.Forms.TextRenderer.DrawText(g, drawstr, _font, new Point(0, 0), fontColor); } #if debug表示 g.DrawRectangle(new Pen(Color.White, 1), new Rectangle(1, 1, stringSize.Width - 1, stringSize.Height - 1)); g.DrawRectangle(new Pen(Color.Green, 1), new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1)); #endif _rectStrings = new Rectangle(0, 0, stringSize.Width, stringSize.Height); _ptOrigin = new Point(nEdgePt * 2, nEdgePt * 2); #region [ リソースを解放する ] if (sf != null) { sf.Dispose(); } sf = null; if (g != null) { g.Dispose(); } g = null; #endregion return(bmp); }
/// <summary>This method will paint the group title.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintGroupText(System.Drawing.Graphics g) { //Check if string has something------------- if (this.Text == string.Empty) { return; } //------------------------------------------ //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ SizeF StringSize = g.MeasureString(this.Text, this.Font); Size StringSize2 = StringSize.ToSize(); if (this.GroupImage != null) { StringSize2.Width += 18; } int ArcWidth = this.RoundCorners; int ArcHeight = this.RoundCorners; int ArcX1 = 20; int ArcX2 = (StringSize2.Width + 34) - (ArcWidth + 1); int ArcY1 = 0; int ArcY2 = 24 - (ArcHeight + 1); if (this.TitleStyle == TitleStyles.XPStyle) { ArcX1 = 0; ArcX2 = this.Width - (ArcWidth + 1); ArcY1 = 0; ArcY2 = 24 - (ArcHeight + 1); } System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = null;//(this.PaintGroupBox) ? new LinearGradientBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush TextColorBrush = new SolidBrush(this.TitleTextColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Create Rounded Rectangle Path------ path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left path.CloseAllFigures(); //----------------------------------- //Check if Gradient Mode is enabled-- if (this.PaintGroupBox) { //Paint Rounded Rectangle------------ BackgroundGradientBrush = new LinearGradientBrush(path.GetBounds(), this.TitileGradientColors.Color1, this.TitileGradientColors.Color2, (LinearGradientMode)this.BackgroundGradientMode); g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } else { if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ BackgroundBrush = new SolidBrush(this.BackColor); g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.GradientColors.Color1, this.GradientColors.Color2, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } } //----------------------------------- //Paint Borded----------------------- g.DrawPath(BorderPen, path); //----------------------------------- //Paint Text------------------------- int CustomStringWidth = (this.GroupImage != null) ? 44 : 28; g.DrawString(this.Text, this.Font, TextColorBrush, CustomStringWidth, 5); //----------------------------------- //Draw GroupImage if there is one---- if (this.GroupImage != null) { g.DrawImage(this.GroupImage, 28, 4, 16, 16); } //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (TextColorBrush != null) { TextColorBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }
/// <summary>This method will paint the control.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintBack(System.Drawing.Graphics g) { //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ int ArcWidth = this.RoundCorners * 2; int ArcHeight = this.RoundCorners * 2; int ArcX1 = 0; int ArcX2 = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1); int ArcY1 = 10; int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Create Rounded Rectangle Path------ path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left path.CloseAllFigures(); //----------------------------------- //Check if Gradient Mode is enabled-- if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.GradientColors.Color1, this.GradientColors.Color2, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } //----------------------------------- //Paint Borded----------------------- g.DrawPath(BorderPen, path); //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }
private void OnDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); Rectangle rect = e.Bounds; rect.X += 1; rect.Y += 1; rect.Height -= 2; rect.Width = rect.Height; System.Drawing.Brush brush = new System.Drawing.SolidBrush(Color.White); System.Drawing.Brush fill = new System.Drawing.SolidBrush(Color.LightSteelBlue); System.Drawing.Pen pen = new System.Drawing.Pen(Color.Black, 0); e.Graphics.FillRectangle(brush, rect); e.Graphics.DrawRectangle(pen, rect); System.Drawing.Drawing2D.SmoothingMode mode = e.Graphics.SmoothingMode; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; rect.Inflate(-2, -2); string shapeId = _list.Items[e.Index].ToString(); ShapeTemplate shape = ShapeTemplate.FromId(shapeId); RectangleF rectf = new RectangleF( (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height); MindFusion.FlowChartX.ShapeTemplate.PathData data = shape.initData(rectf, 0); System.Drawing.Drawing2D.GraphicsPath path = shape.getPath(data, 0); e.Graphics.FillPath(fill, path); e.Graphics.DrawPath(pen, path); path.Dispose(); path = shape.getDecorationPath(data, 0); if (path != null) { e.Graphics.DrawPath(pen, path); path.Dispose(); } e.Graphics.SmoothingMode = mode; pen.Dispose(); fill.Dispose(); brush.Dispose(); // Draw the text; rectf.X = rectf.Right + 6; rectf.Width = (float)e.Bounds.Width - rectf.X; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center; System.Drawing.Brush textBrush = new System.Drawing.SolidBrush(Color.Black); e.Graphics.DrawString(shapeId, Font, textBrush, rectf, format); textBrush.Dispose(); format.Dispose(); }
internal void Dispose(bool disposing) { path.Dispose(); }
private void PathGradient_Paint(object sender, PaintEventArgs e) { GraphicsPath path = new GraphicsPath(); int size = 150; path.AddEllipse(10, 10, size, size); PathGradientBrush brush = new PathGradientBrush(path); brush.WrapMode = WrapMode.Tile; brush.SurroundColors = new Color[] { Color.White }; brush.CenterColor = Color.Violet; e.Graphics.FillRectangle(brush, 10, 10, size, size); path.Dispose(); brush.Dispose(); }