// paramters: // pen 绘制边框。可以为null,那样就整体一个填充色,没有边框 // brush 绘制填充色。可以为null,那样就只有边框 public static void RoundRectangle(Graphics graphics, Pen pen, Brush brush, float x, float y, float width, float height, float radius) { using (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); // Corner 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(); if (brush != null) graphics.FillPath(brush, path); if (pen != null) graphics.DrawPath(pen, path); } }
public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddLine(Location.X, Location.Y + ModelSize.Height / 3, Location.X + ModelSize.Width, Location.Y + ModelSize.Height / 3); path.CloseFigure(); path.StartFigure(); path.AddLine(Location.X, Location.Y + (ModelSize.Height / 3) * 2, Location.X + ModelSize.Width, Location.Y + (ModelSize.Height * 2) / 3); path.CloseFigure(); path.AddEllipse(new RectangleF(Location, ModelSize)); path.CloseFigure(); path.Transform(this.TMatrix.TransformationMatrix); Pen pen = new Pen(this.BorderColor, this.BorderWidth); if (IS_FILLED) { SolidBrush brush = new SolidBrush(this.FillColor); graphics.FillPath(brush, path); } graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
/// <summary> /// Изчертава елипсите. /// </summary> /// <param name="graphics"></param> public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddEllipse(Location.X + ModelSize.Width / 3, Location.Y + ModelSize.Height / 3, ModelSize.Width / 3, ModelSize.Height / 3); path.CloseFigure(); path.StartFigure(); path.AddLine(Location.X + (ModelSize.Width * 2) / 3, Location.Y + ModelSize.Height / 2, Location.X + ModelSize.Width, Location.Y + ModelSize.Height / 2); path.CloseFigure(); path.AddEllipse(new RectangleF(Location, ModelSize)); path.CloseFigure(); path.Transform(this.TMatrix.TransformationMatrix); /* * Създава се Pen, който изчертава контура, като използва * цвят и дебелина (определят се от конструктора) */ Pen pen = new Pen(this.BorderColor, this.BorderWidth); // Правим същото, но за запълването if (IS_FILLED) { SolidBrush brush = new SolidBrush(this.FillColor); graphics.FillPath(brush, path); } graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
/// <summary> /// Creates a pattern symbolizing a linestring like this <c>>>>>></c> /// </summary> /// <param name="x">The length of the peak</param> /// <param name="y">the offset left and right from the original line</param> /// <returns>The pattern</returns> public static GraphicsPath GetGreaterSeries(float x, float y) { var gp = new GraphicsPath(); gp.AddLine(new PointF(0.5f*x, y), new PointF(1.5f * x, 0f)); gp.CloseFigure(); gp.AddLine(new PointF(1.5f * x, 0f), new PointF(0.5f*x, -y)); gp.CloseFigure(); return gp; }
/// <summary> /// Create a "zigzag" pattern, sort of like a rotated by 90 degree Z /// </summary> /// <param name="x">The width of a step op the linestring axis.</param> /// <param name="y">The offset left and right from the axis.</param> /// <returns>The pattern</returns> public static GraphicsPath GetZigZag(float x, float y) { var gp = new GraphicsPath(); gp.AddLine(new PointF(0f, 0f), new PointF(0f, y)); gp.CloseFigure(); gp.AddLine(new PointF(0f, y), new PointF(2*x, -y)); gp.CloseFigure(); gp.AddLine(new PointF(2*x, -y), new PointF(2*x, 0)); gp.CloseFigure(); return gp; }
/// <summary> /// Creates a triangle pattern /// </summary> /// <param name="x">The base length of the triangle</param> /// <param name="y">The location of the next triangle</param> /// <returns></returns> public static GraphicsPath GetTriangleSeries(float x, float y) { var gp = new GraphicsPath(); gp.AddPolygon(new[] { new PointF(x, 0f), new PointF(0f, 0f), new PointF(0.5f*x, 2f*x/3f), new PointF(x, 0f) }); gp.CloseFigure(); //Just to move to a new position gp.AddEllipse(y, 0f, 0f, 0f); gp.CloseFigure(); return gp; }
private void Form1_Paint(object sender, PaintEventArgs e) { GraphicsPath Path = new GraphicsPath(); Path.AddLine(10, 10, 50, 50); Path.AddLine(100, 50, 140, 10); Path.CloseFigure(); Path.StartFigure(); Path.AddLine(140, 80, 100, 120); Path.AddLine(100, 150, 140, 190); Path.CloseFigure(); e.Graphics.DrawPath(Pens.Black, Path); }
public override RectangleF ReturnBounds() { GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddLine(Location.X, Location.Y + ModelSize.Height / 3, Location.X + ModelSize.Width, Location.Y + ModelSize.Height / 3); path.CloseFigure(); path.StartFigure(); path.AddLine(Location.X, Location.Y + (ModelSize.Height / 3) * 2, Location.X + ModelSize.Width, Location.Y + (ModelSize.Height * 2) / 3); path.CloseFigure(); path.AddEllipse(new RectangleF(Location, ModelSize)); path.CloseFigure(); path.Transform(this.TMatrix.TransformationMatrix); return path.GetBounds(); }
private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Point[] points = { new Point(5,10) , new Point(23 , 130), new Point(130 , 57) }; GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddEllipse(170 , 170 , 100 , 50); g.FillPath(Brushes.Black, path); path.CloseFigure(); path.StartFigure(); path.AddCurve(points , 0.5F); g.FillPath(Brushes.Blue, path); //coords g.TranslateTransform(40, 40); Point A = new Point(0, 0); Point B = new Point(150 , 150); g.DrawLine(new Pen(Brushes.Black, 3), A, B); g.Dispose(); }
private void RecreatePath() { path = new GraphicsPath(); if (tlRad > 0) path.AddArc(AbsoluteX, AbsoluteY, tlRad, tlRad, 180, 90); else path.AddLine(AbsoluteX, AbsoluteY, AbsoluteX, AbsoluteY); if (trRad > 0) path.AddArc(AbsoluteX + ActualWidth - trRad, AbsoluteY, trRad, trRad, 270, 90); else path.AddLine(AbsoluteX + ActualWidth, AbsoluteY, AbsoluteX + ActualWidth, AbsoluteY); if (brRad > 0) path.AddArc(AbsoluteX + ActualWidth - brRad, AbsoluteY + ActualHeight - brRad, brRad, brRad, 0, 90); else path.AddLine(AbsoluteX + ActualWidth, AbsoluteY + ActualHeight, AbsoluteX + ActualWidth, AbsoluteY + ActualHeight); if (blRad > 0) path.AddArc(AbsoluteX, AbsoluteY + ActualHeight - blRad, blRad, blRad, 90, 90); else path.AddLine(AbsoluteX, AbsoluteY + ActualHeight, AbsoluteX, AbsoluteY + ActualHeight); path.CloseFigure(); }
// Create a rounded rectangle path with a given Rectangle and a given corner Diameter public static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, float diameter) { GraphicsPath path = new GraphicsPath (); RectangleF arcrect = new RectangleF (rect.Location, new SizeF (diameter, diameter)); // Top left arc path.AddArc (arcrect, 190, 90); path.AddLine (rect.Left + (int)(diameter / 2), rect.Top, rect.Left + rect.Width - (int)(diameter / 2), rect.Top); // Top right arc arcrect.X = rect.Right - diameter; path.AddArc (arcrect, 270, 90); path.AddLine (rect.Left + rect.Width, rect.Top + (int)(diameter / 2), rect.Left + rect.Width, rect.Top + rect.Height - (int)(diameter / 2)); // Bottom right arc arcrect.Y = rect.Bottom - diameter; path.AddArc (arcrect, 0, 90); // Bottom left arc arcrect.X = rect.Left; path.AddArc (arcrect, 90, 90); path.CloseFigure (); return path; }
public static void DrawRoundedRectangle(Graphics newGraphics, Color boxColor, Color gradFillColor1, Color gradFillColor2, int xPosition, int yPosition, int height, int width, int cornerRadius) { using (var boxPen = new Pen(boxColor)) { using (var path = new GraphicsPath()) { path.AddLine(xPosition + cornerRadius, yPosition, xPosition + width - (cornerRadius * 2), yPosition); path.AddArc(xPosition + width - (cornerRadius * 2), yPosition, cornerRadius * 2, cornerRadius * 2, 270, 90); path.AddLine(xPosition + width, yPosition + cornerRadius, xPosition + width, yPosition + height - (cornerRadius * 2)); path.AddArc(xPosition + width - (cornerRadius * 2), yPosition + height - (cornerRadius * 2), cornerRadius * 2, cornerRadius * 2, 0, 90); path.AddLine(xPosition + width - (cornerRadius * 2), yPosition + height, xPosition + cornerRadius, yPosition + height); path.AddArc(xPosition, yPosition + height - (cornerRadius * 2), cornerRadius * 2, cornerRadius * 2, 90, 90); path.AddLine(xPosition, yPosition + height - (cornerRadius * 2), xPosition, yPosition + cornerRadius); path.AddArc(xPosition, yPosition, cornerRadius * 2, cornerRadius * 2, 180, 90); path.CloseFigure(); newGraphics.DrawPath(boxPen, path); var b = new LinearGradientBrush(new Point(xPosition, yPosition), new Point(xPosition + width, yPosition + height), gradFillColor1, gradFillColor2); newGraphics.FillPath(b, path); } } }
public static GraphicsPath CreateRoundedRectangle(SizeF size, PointF location) { int cornerSize = (int)GraphConstants.CornerSize * 2; int connectorSize = (int)GraphConstants.ConnectorSize; int halfConnectorSize = (int)Math.Ceiling(connectorSize / 2.0f); var height = size.Height; var width = size.Width; var halfWidth = width / 2.0f; var halfHeight = height / 2.0f; var connectorOffset = (int)Math.Floor((GraphConstants.MinimumItemHeight - GraphConstants.ConnectorSize) / 2.0f); var left = location.X; var top = location.Y; var right = location.X + width; var bottom = location.Y + height; var path = new GraphicsPath(FillMode.Winding); path.AddArc(left, top, cornerSize, cornerSize, 180, 90); path.AddArc(right - cornerSize, top, cornerSize, cornerSize, 270, 90); path.AddArc(right - cornerSize, bottom - cornerSize, cornerSize, cornerSize, 0, 90); path.AddArc(left, bottom - cornerSize, cornerSize, cornerSize, 90, 90); path.CloseFigure(); return path; }
/// <summary> /// 建立带有圆角样式的路径。 /// </summary> /// <param name="rect">用来建立路径的矩形。</param> /// <param name="radius">圆角的大小。</param> /// <returns>建立的路径。</returns> public static GraphicsPath CreateRoundPath(Rectangle rect, int radius) { GraphicsPath path = new GraphicsPath(); int radiusCorrection = 1; path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); path.CloseFigure(); return path; }
public ProgressControl() { SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); pnOutln = new Pen(cOutln, iOutlln); rcArea = new Rectangle[5]; for (int i = 0; i < 5; ++i) { rcArea[i].X = i * (iWidth + iPad); rcArea[i].Width = iWidth + iPad; rcArea[i].Height = iHeight; } //setup arrow shape gpBlock = new GraphicsPath(); gpBlock.AddLines(new PointF[] { new PointF(0, 0), //TL new PointF(iWidth - iPad, 0), //TR new PointF(iWidth, iHeight / 2), //MR new PointF(iWidth - iPad, iHeight), //BR new PointF(0, iHeight), //BL new PointF(iPad, iHeight / 2) //ML }); gpBlock.CloseFigure(); }
private static GraphicsPath GenerateCapsule( this Graphics graphics, RectangleF rectangle ) { float diameter; RectangleF arc; GraphicsPath path = new GraphicsPath(); try { if( rectangle.Width > rectangle.Height ) { diameter = rectangle.Height; SizeF sizeF = new SizeF( diameter, diameter ); arc = new RectangleF( rectangle.Location, sizeF ); path.AddArc( arc, 90, 180 ); arc.X = rectangle.Right - diameter; path.AddArc( arc, 270, 180 ); } else if( rectangle.Width < rectangle.Height ) { diameter = rectangle.Width; SizeF sizeF = new SizeF( diameter, diameter ); arc = new RectangleF( rectangle.Location, sizeF ); path.AddArc( arc, 180, 180 ); arc.Y = rectangle.Bottom - diameter; path.AddArc( arc, 0, 180 ); } else path.AddEllipse( rectangle ); } catch { path.AddEllipse( rectangle ); } finally { path.CloseFigure(); } return path; }
private GraphicsPath CreateRoundRect(Rectangle rect, int radius) { GraphicsPath gp = new GraphicsPath(); int x = rect.X; int y = rect.Y; int width = rect.Width; int height = rect.Height; if (radius > 0) { radius = Math.Min(radius, height / 2 - 1); radius = Math.Min(radius, width / 2 - 1); 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); } else { gp.AddRectangle(rect); } gp.CloseFigure(); return gp; }
public static void DrawArc(Rectangle re, GraphicsPath pa, int radius, EGroupPos _grouppos) { int radiusX0Y0 = radius, radiusXfy0 = radius, radiusX0Yf = radius, radiusXfyf = radius; switch (_grouppos) { case EGroupPos.Left: radiusXfy0 = 1; radiusXfyf = 1; break; case EGroupPos.Center: radiusX0Y0 = 1; radiusX0Yf = 1; radiusXfy0 = 1; radiusXfyf = 1; break; case EGroupPos.Right: radiusX0Y0 = 1; radiusX0Yf = 1; break; case EGroupPos.Top: radiusX0Yf = 1; radiusXfyf = 1; break; case EGroupPos.Bottom: radiusX0Y0 = 1; radiusXfy0 = 1; break; } pa.AddArc(re.X, re.Y, radiusX0Y0, radiusX0Y0, 180, 90); pa.AddArc(re.Width - radiusXfy0, re.Y, radiusXfy0, radiusXfy0, 270, 90); pa.AddArc(re.Width - radiusXfyf, re.Height - radiusXfyf, radiusXfyf, radiusXfyf, 0, 90); pa.AddArc(re.X, re.Height - radiusX0Yf, radiusX0Yf, radiusX0Yf, 90, 90); pa.CloseFigure(); }
/// <summary> /// Initializes the control with default values /// </summary> public StarRatingControl() { SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.ResizeRedraw, true); pnOutln = new Pen(cOutln, iOutThick); rcArea = new Rectangle[iStarCount]; for (int i = 0; i < iStarCount; ++i) { rcArea[i].X = i * (iWidth + iPadding); rcArea[i].Width = iWidth + iPadding; rcArea[i].Height = iHeight; } //setup star shape (from top tip and in thirds) gpStar = new GraphicsPath(); PointF[] pfStar = new PointF[10]; pfStar[0] = new PointF(iWidth / 2, 0); //12:00 pfStar[1] = new PointF(2 * iWidth / 3, iHeight / 3); //01:00 pfStar[2] = new PointF(iWidth, iHeight / 3); //02:00 pfStar[3] = new PointF(4 * iWidth / 5, 4 * iHeight / 7); //03:00 pfStar[4] = new PointF(5 * iWidth / 6, iHeight); //04:00 pfStar[5] = new PointF(iWidth / 2, 4 * iHeight / 5); //06:00 pfStar[6] = new PointF(iWidth - pfStar[4].X, pfStar[4].Y); //08:00 pfStar[7] = new PointF(iWidth - pfStar[3].X, pfStar[3].Y); //09:00 pfStar[8] = new PointF(iWidth - pfStar[2].X, pfStar[2].Y); //10:00 pfStar[9] = new PointF(iWidth - pfStar[1].X, pfStar[1].Y); //11:00 gpStar.AddLines(pfStar); gpStar.CloseFigure(); }
private static GraphicsPath GetRoundedRect(RectangleF baseRect, float radius) { if (radius <= 0.0F) { GraphicsPath mPath = new GraphicsPath(); mPath.AddRectangle(baseRect); mPath.CloseFigure(); return(mPath); } if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0) { return(GetCapsule(baseRect)); } float diameter = radius * 2.0F; SizeF sizeF = new SizeF(diameter, diameter); RectangleF arc = new RectangleF(baseRect.Location, sizeF); GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(arc, 180, 90); arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 90); arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 90); arc.X = baseRect.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); return(path); }
private GraphicsPath GetRoundedRect() { float diameter = _roundedRadius * 2.0F; var sizeF = new SizeF(diameter, diameter); var arc = new RectangleF(new Point(-1, -1), sizeF); var path = new System.Drawing.Drawing2D.GraphicsPath(); // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = this.ClientRectangle.Right - diameter; path.AddArc(arc, 270, 90); // bottom right arc arc.Y = this.ClientRectangle.Bottom - diameter; path.AddArc(arc, 0, 90); // bottom left arc arc.X = -1; path.AddArc(arc, 90, 90); path.CloseFigure(); return(path); }
//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; } }
protected override void Draw(Graphics g) { regionFillPath = new GraphicsPath(); for (int i = 0; i < nodes.Count - 1; i++) { regionFillPath.AddLine(nodes[i].Position, nodes[i + 1].Position); } if (nodes.Count > 2) { regionFillPath.CloseFigure(); using (Region region = new Region(regionFillPath)) { g.ExcludeClip(region); g.FillRectangle(shadowBrush, 0, 0, Width, Height); g.ResetClip(); } g.DrawRectangleProper(borderPen, currentArea); } else { g.FillRectangle(shadowBrush, 0, 0, Width, Height); } if (nodes.Count > 1) { g.DrawPath(borderPen, regionFillPath); } base.Draw(g); }
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(); }
private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius) { int diameter = radius; Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter)); GraphicsPath path = new GraphicsPath(); // 左上角 path.AddArc(arcRect, 180, 90); // 右上角 arcRect.X = rect.Right - diameter; path.AddArc(arcRect, 270, 90); // 右下角 arcRect.Y = rect.Bottom - diameter; path.AddArc(arcRect, 0, 90); // 左下角 arcRect.X = rect.Left; path.AddArc(arcRect, 90, 90); path.CloseFigure(); return path; }
/// <summary> /// Roundeds the rect. /// </summary> /// <param name="baseRect">The base rect.</param> /// <param name="cornerRadius">The corner radius.</param> /// <returns>System.Drawing.Drawing2D.GraphicsPath.</returns> public static System.Drawing.Drawing2D.GraphicsPath RoundedRect( System.Drawing.Rectangle baseRect, int cornerRadius) { int diameter = cornerRadius * 2; System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Rectangle rectTopLeft = new System.Drawing.Rectangle( baseRect.Left, baseRect.Top, diameter, diameter); System.Drawing.Rectangle rectTopRight = new System.Drawing.Rectangle( baseRect.Right - diameter, baseRect.Top, diameter, diameter); System.Drawing.Rectangle rectBottomLeft = new System.Drawing.Rectangle( baseRect.Left, baseRect.Bottom - diameter, diameter, diameter); System.Drawing.Rectangle rectBottomRight = new System.Drawing.Rectangle( baseRect.Right - diameter, baseRect.Bottom - diameter, diameter, diameter); gp.AddArc(rectTopLeft, 180, 90); gp.AddArc(rectTopRight, 270, 90); gp.AddArc(rectBottomRight, 0, 90); gp.AddArc(rectBottomLeft, 90, 90); gp.CloseFigure(); return(gp); }
private GraphicsPath GetRoundedRect(RectangleF baseRect, float radius) { float diameter = radius * 2.0F; SizeF sizeF = new SizeF(diameter, diameter); RectangleF arc = new RectangleF(baseRect.Location, sizeF); GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 90); // bottom right arc arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 90); // bottom left arc arc.X = baseRect.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); return(path); }
public TButton() : base() { Point[] pts = { new Point(0, _buttonsize / 2 - 1), new Point(_buttonsize / 2 - 1, 0), new Point(_buttonsize , _buttonsize / 2 - 1), new Point(_buttonsize , _buttonsize / 2 + 2), new Point(_buttonsize / 2 + 2, _buttonsize - 1), new Point(_buttonsize / 2 - 1, _buttonsize - 1) }; GraphicsPath p = new GraphicsPath(); p.AddPolygon(pts); p.CloseFigure(); p.FillMode = FillMode.Alternate; this.Region = new Region(p); ImageList = new System.Windows.Forms.ImageList(); ImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit; ImageList.ImageSize = new System.Drawing.Size(_buttonsize, _buttonsize); ImageList.Images.Add(((System.Drawing.Image)(Resource1.ResourceManager.GetObject("diamond1")))); ImageList.Images.Add(((System.Drawing.Image)(Resource1.ResourceManager.GetObject("diamond1_down")))); ImageIndex = 0; }
protected override void Draw(Graphics g) { g.SmoothingMode = SmoothingMode.HighQuality; regionFillPath = new GraphicsPath(); for (int i = 0; i < nodes.Count - 1; i++) { regionFillPath.AddLine(nodes[i].Position, nodes[i + 1].Position); } if (nodes.Count > 2) { regionFillPath.CloseFigure(); using (Region region = new Region(regionFillPath)) { g.Clip = region; g.FillRectangle(lightBackgroundBrush, ScreenRectangle0Based); g.ResetClip(); } g.DrawRectangleProper(borderPen, currentArea); } if (nodes.Count > 1) { g.DrawPath(borderPen, regionFillPath); g.DrawPath(borderDotPen, regionFillPath); } base.Draw(g); }
public override void Draw(Graphics g) { System.Drawing.Size st = g.MeasureString(Marker.ToolTipText, Font).ToSize(); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y - st.Height, st.Width + TextPadding.Width, st.Height + TextPadding.Height); rect.Offset(Offset.X, Offset.Y); using(GraphicsPath objGP = new GraphicsPath()) { objGP.AddLine(rect.X + 2 * Radius, rect.Y + rect.Height, rect.X + Radius, rect.Y + rect.Height + Radius); objGP.AddLine(rect.X + Radius, rect.Y + rect.Height + Radius, rect.X + Radius, rect.Y + rect.Height); objGP.AddArc(rect.X, rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 90, 90); objGP.AddLine(rect.X, rect.Y + rect.Height - (Radius * 2), rect.X, rect.Y + Radius); objGP.AddArc(rect.X, rect.Y, Radius * 2, Radius * 2, 180, 90); objGP.AddLine(rect.X + Radius, rect.Y, rect.X + rect.Width - (Radius * 2), rect.Y); objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y, Radius * 2, Radius * 2, 270, 90); objGP.AddLine(rect.X + rect.Width, rect.Y + Radius, rect.X + rect.Width, rect.Y + rect.Height - (Radius * 2)); objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 0, 90); // Corner objGP.CloseFigure(); g.FillPath(Fill, objGP); g.DrawPath(Stroke, objGP); } #if !PocketPC g.DrawString(Marker.ToolTipText, Font, Brushes.Navy, rect, Format); #else g.DrawString(ToolTipText, ToolTipFont, TooltipForeground, rect, ToolTipFormat); #endif }
public static GraphicsPath GetRoundedRectangle(RectangleF rect, float arcRadius) { var x = rect.X; var y = rect.Y; var w = rect.Width; var h = rect.Height; var d = 2 * arcRadius; var gp = new GraphicsPath(); if(arcRadius == 0) { gp.AddRectangle(rect); } else { gp.AddArc(x, y, d, d, 180, 90); gp.AddLine(x + arcRadius, y, x + w - arcRadius - 1, y); gp.AddArc(x + w - d - 1, y, d, d, 270, 90); gp.AddLine(x + w - 1, y + arcRadius, x + w - 1, y + h - arcRadius - 1); gp.AddArc(x + w - d - 1, y + h - d - 1, d, d, 0, 90); gp.AddLine(x + w - arcRadius - 1, y + h - 1, x + arcRadius, y + h - 1); gp.AddArc(x, y + h - d - 1, d, d, 90, 90); gp.AddLine(x, y + h - arcRadius - 1, x, y + arcRadius); } gp.CloseFigure(); return gp; }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (BorderRadius == 0) { Rectangle rc = ClientRectangle; rc.Inflate(-(int)Math.Round(BorderWidth / 2.0 + .5), -(int)Math.Round(BorderWidth / 2.0 + .5)); rc.Y = rc.Y - 1; rc.Height = rc.Height + 1; e.Graphics.DrawRectangle(new Pen(BorderColor, BorderWidth), rc); } else { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; GraphicsPath gp = Extensions.Create(0, 0, Width - 2, Height - 2, BorderRadius); Pen p = new Pen(BorderColor, BorderWidth); e.Graphics.DrawPath(p, gp); e.Graphics.FillPath(p.Brush, gp); StringFormat formatting = (StringFormat)StringFormat.GenericTypographic.Clone(); formatting.Alignment = StringAlignment.Center; formatting.LineAlignment = StringAlignment.Center; float emsize = e.Graphics.DpiY * Font.Size / 72; gp = new GraphicsPath(); gp.StartFigure(); gp.AddString(Text, Font.FontFamily, (int)Font.Style, emsize, new Point(Width / 2, Height / 2), formatting); gp.CloseFigure(); e.Graphics.FillPath(new Pen(ForeColor, 1).Brush, gp); } }
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(); }
private GraphicsPath GetCornerRect(RectangleF baseRect, float ratio) { GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); float radius = Math.Min(baseRect.Width, baseRect.Height) * ratio; PointF[] points = new PointF[8]; points[0].X = baseRect.Left; points[0].Y = baseRect.Top + radius; points[1].X = points[0].X + radius; points[1].Y = baseRect.Top; points[2].X = points[0].X + baseRect.Width - radius; points[2].Y = points[1].Y; points[3].X = points[0].X + baseRect.Width; points[3].Y = points[0].Y; points[4].X = points[3].X; points[4].Y = baseRect.Bottom - radius; points[5].X = points[2].X; points[5].Y = baseRect.Bottom; points[6].X = points[1].X; points[6].Y = points[5].Y; points[7].X = points[0].X; points[7].Y = points[4].Y; path.AddLines(points); path.CloseFigure(); return(path); }
private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; //Создаем массив точек Point[] points = { new Point(5, 10), new Point(23, 130), new Point(130, 57)}; GraphicsPath path = new GraphicsPath(); //рисуем первую траекторию path.StartFigure(); path.AddEllipse(170, 170, 100, 50); // заливаем траекторию цветом g.FillPath(Brushes.Aqua, path); //рисуем вторую траекторию path.StartFigure(); path.AddCurve(points, 0.5F); path.AddArc(100, 50, 100, 100, 0, 120); path.AddLine(50, 150, 50, 220); // Закрываем траекторию path.CloseFigure(); //рисуем четвертую траекторию path.StartFigure(); path.AddArc(180, 30, 60, 60, 0, -170); g.DrawPath(new Pen(Color.Blue, 3), path); g.Dispose(); }
/// <summary> /// Gets the tab path. /// </summary> /// <param name="index">The index.</param> /// <returns>GraphicsPath.</returns> private GraphicsPath GetTabPath(int index) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.Reset(); Rectangle rect = this.GetTabRect(index); switch (Alignment) { case TabAlignment.Top: break; case TabAlignment.Bottom: break; case TabAlignment.Left: break; case TabAlignment.Right: break; } int PaddingTop = 10; Point P_LeftTop = new Point(rect.Left + 7, rect.Top + PaddingTop); Point P_LeftBottom = new Point(rect.Left + 1, rect.Bottom); Point P_RightTop = new Point(rect.Right - 7, rect.Top + PaddingTop); Point P_RightBottom = new Point(rect.Right - 1, rect.Bottom); Point P_Control1 = new Point(rect.Left + 3, rect.Top + PaddingTop); Point P_Control2 = new Point(rect.Left + 2, rect.Bottom - rect.Height / 2); Point P_Control3 = new Point(rect.Right - 3, rect.Top + PaddingTop); Point P_Control4 = new Point(rect.Right - 2, rect.Bottom - rect.Height / 2); //path.AddLine(rect.Left + 15, rect.Top, rect.Left + 2, rect.Bottom + 1); //path.AddLine(rect.Left + 15, rect.Top, rect.Right - 15, rect.Top); //path.AddLine(rect.Right - 15, rect.Top, rect.Right - 2, rect.Bottom + 1); //path.AddLine(rect.Right - 2, rect.Bottom, rect.Left + 2, rect.Bottom); path.AddBezier(P_LeftTop, P_Control1, P_Control2, P_LeftBottom); path.AddLine(P_LeftBottom, P_RightBottom); path.AddBezier(P_RightBottom, P_Control4, P_Control3, P_RightTop); //path.AddBezier(P_RightTop, P_Control3, P_Control4, P_RightBottom); path.AddLine(P_RightTop, P_LeftTop); //int diameter = 2 * 10; //path.AddArc(new Rectangle(new Point(rect.Left + 5, rect.Top), new Size(diameter, diameter)), 180, 60); //path.AddArc(new Rectangle(new Point(rect.Right - 15 - diameter, rect.Top - diameter), new Size(diameter, diameter)), 0, 60); path.CloseFigure(); //return GetRoundedRectPath(rect, 15); return(path); }
private GraphicsPath GetRoundedRect(RectangleF baseRect, float radius) { // if corner radius is less than or equal to zero, // return the original rectangle if (radius <= 0.0F) { GraphicsPath mPath = new GraphicsPath(); mPath.AddRectangle(baseRect); mPath.CloseFigure(); return(mPath); } // if the corner radius is greater than or equal to // half the width, or height (whichever is shorter) // then return a capsule instead of a lozenge if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0) { return(GetCapsule(baseRect)); } // create the arc for the rectangle sides and declare // a graphics path object for the drawing float diameter = radius * 2.0F; SizeF sizeF = new SizeF(diameter, diameter); RectangleF arc = new RectangleF(baseRect.Location, sizeF); GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 90); // bottom right arc arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 90); // bottom left arc arc.X = baseRect.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); return(path); }
public static System.Drawing.Drawing2D.GraphicsPath RoundRectangle(Rectangle R, int Curve) { System.Drawing.Drawing2D.GraphicsPath GP = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding); GP.AddArc(R.X, R.Y, Curve, Curve, 180.0F, 90.0F); GP.AddArc(R.Right - Curve, R.Y, Curve, Curve, 270.0F, 90.0F); GP.AddArc(R.Right - Curve, R.Bottom - Curve, Curve, Curve, 0.0F, 90.0F); GP.AddArc(R.X, R.Bottom - Curve, Curve, Curve, 90.0F, 90.0F); GP.CloseFigure(); return(GP); }
/// <summary> /// Добавляет окружность по градусам от определённого градуса. /// </summary> /// <param name="Center"></param> /// <param name="StartAngle"></param> /// <param name="SweepAngle"></param> /// <param name="Radius"></param> /// <returns></returns> public static GraphicsPath EllipseByDegrees(Point Center, Int32 StartAngle, Int32 SweepAngle, Int32 Radius) { System.Drawing.Drawing2D.GraphicsPath GP = new System.Drawing.Drawing2D.GraphicsPath(); GP.AddArc(new Rectangle(Center.X - Radius, Center.Y - Radius, Radius * 2, Radius * 2), StartAngle, SweepAngle); GP.AddLine( new Point(((int)Math.Cos(SweepAngle) * Radius + Center.X + Radius) - Radius, (int)Math.Sin(SweepAngle) * Radius + Center.Y), Center); GP.CloseFigure(); return(GP); }
public static System.Drawing.Drawing2D.GraphicsPath CreateGraphicsPath(VertexStoreSnap vxsSnap) { VertexSnapIter vxsIter = vxsSnap.GetVertexSnapIter(); double prevX = 0; double prevY = 0; double prevMoveToX = 0; double prevMoveToY = 0; var brush_path = new System.Drawing.Drawing2D.GraphicsPath(FillMode.Winding);//*** winding for overlapped path for (;;) { double x, y; VertexCmd cmd = vxsIter.GetNextVertex(out x, out y); switch (cmd) { case PixelFarm.Agg.VertexCmd.MoveTo: prevMoveToX = prevX = x; prevMoveToY = prevY = y; brush_path.StartFigure(); break; case PixelFarm.Agg.VertexCmd.LineTo: brush_path.AddLine((float)prevX, (float)prevY, (float)x, (float)y); prevX = x; prevY = y; break; case PixelFarm.Agg.VertexCmd.CloseAndEndFigure: //from current point // brush_path.AddLine((float)prevX, (float)prevY, (float)prevMoveToX, (float)prevMoveToY); prevX = prevMoveToX; prevY = prevMoveToY; brush_path.CloseFigure(); break; case PixelFarm.Agg.VertexCmd.EndFigure: goto EXIT_LOOP; break; case PixelFarm.Agg.VertexCmd.HasMore: break; case PixelFarm.Agg.VertexCmd.Stop: goto EXIT_LOOP; default: throw new NotSupportedException(); } } EXIT_LOOP: return(brush_path); }
public static System.Drawing.Drawing2D.GraphicsPath CreateGraphicsPath(VertexStore vxs) { //render vertice in store int vcount = vxs.Count; double prevX = 0; double prevY = 0; double prevMoveToX = 0; double prevMoveToY = 0; var brush_path = new System.Drawing.Drawing2D.GraphicsPath(FillMode.Winding);//*** winding for overlapped path for (int i = 0; i < vcount; ++i) { double x, y; PixelFarm.Agg.VertexCmd cmd = vxs.GetVertex(i, out x, out y); switch (cmd) { case PixelFarm.Agg.VertexCmd.MoveTo: prevMoveToX = prevX = x; prevMoveToY = prevY = y; brush_path.StartFigure(); break; case PixelFarm.Agg.VertexCmd.LineTo: brush_path.AddLine((float)prevX, (float)prevY, (float)x, (float)y); prevX = x; prevY = y; break; case PixelFarm.Agg.VertexCmd.CloseAndEndFigure: brush_path.AddLine((float)prevX, (float)prevY, (float)prevMoveToX, (float)prevMoveToY); prevMoveToX = prevX = x; prevMoveToY = prevY = y; brush_path.CloseFigure(); break; case PixelFarm.Agg.VertexCmd.EndFigure: break; case PixelFarm.Agg.VertexCmd.HasMore: break; case PixelFarm.Agg.VertexCmd.Stop: i = vcount + 1; //exit from loop break; default: throw new NotSupportedException(); break; } } return(brush_path); }
internal static System.Drawing.Drawing2D.GraphicsPath CreateRoundedRectanglePath(System.Drawing.Rectangle rect, int cornerRadius) { System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); graphicsPath.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180f, 90f); graphicsPath.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y); graphicsPath.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270f, 90f); graphicsPath.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2); graphicsPath.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0f, 90f); graphicsPath.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom); graphicsPath.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90f, 90f); graphicsPath.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2); graphicsPath.CloseFigure(); return(graphicsPath); }
private static System.Drawing.Drawing2D.GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius) { System.Drawing.Drawing2D.GraphicsPath roundedRect = new System.Drawing.Drawing2D.GraphicsPath(); roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90); roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y); roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90); roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2); roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90); roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom); roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90); roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2); roundedRect.CloseFigure(); return(roundedRect); }
private GraphicsPath GetCapsule(RectangleF baseRect) { float diameter; RectangleF arc; GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); try { if (baseRect.Width > baseRect.Height) { // return horizontal capsule diameter = baseRect.Height; SizeF sizeF = new SizeF(diameter, diameter); arc = new RectangleF(baseRect.Location, sizeF); path.AddArc(arc, 90, 180); arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 180); } else if (baseRect.Width < baseRect.Height) { // return vertical capsule diameter = baseRect.Width; SizeF sizeF = new SizeF(diameter, diameter); arc = new RectangleF(baseRect.Location, sizeF); path.AddArc(arc, 180, 180); arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 180); } else { // return circle path.AddEllipse(baseRect); } } catch (Exception ex) { Console.WriteLine(ex.Message); path.AddEllipse(baseRect); } finally { path.CloseFigure(); } return(path); }
private static GraphicsPath GetRoundedRectanglePath(float x, float y, float width, float height, float radius) { float num = Math.Min(radius * 2f, Math.Max(width, height)); RectangleF rect = new RectangleF(x, y, num, num); GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(rect, 180f, 90f); rect.X = (x + width) - num; path.AddArc(rect, 270f, 90f); rect.Y = (y + height) - num; path.AddArc(rect, 0f, 90f); rect.X = x; path.AddArc(rect, 90f, 90f); path.CloseFigure(); return(path); }
// 绘制圆角矩形函数 private System.Drawing.Drawing2D.GraphicsPath CreateRoundRectPath(Rectangle rect, int radius) { rect.Offset(-1, -1); Rectangle RoundRect = new Rectangle(rect.Location, new Size(radius - 1, radius - 1)); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(RoundRect, 180, 90); // 左上角 RoundRect.X = rect.Right - radius; // 右上角 path.AddArc(RoundRect, 270, 90); RoundRect.Y = rect.Bottom - radius; // 右下角 path.AddArc(RoundRect, 0, 90); RoundRect.X = rect.Left; // 左下角 path.AddArc(RoundRect, 90, 90); path.CloseFigure(); return(path); }
protected GraphicsPath GetGraphicsPath(Rectangle rect) { GraphicsPath ClientPath = new System.Drawing.Drawing2D.GraphicsPath(); if (rect.Width <= 0) { rect.Width = 1; } if (rect.Height <= 0) { rect.Height = 1; } ClientPath.AddRectangle(rect); ClientPath.CloseFigure(); return(ClientPath); }
//#endregion //#region Gets the desired Capsular path. private GraphicsPath GetCapsule(RectangleF baseRect) { float diameter; RectangleF arc; GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); try { if (baseRect.Width > baseRect.Height) { // return horizontal capsule if (baseRect.Height < 0) { Debugger.Break(); } diameter = Math.Max(baseRect.Height, 1); SizeF sizeF = new SizeF(diameter, diameter); arc = new RectangleF(baseRect.Location, sizeF); path.AddArc(arc, 90, 180); arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 180); } else if (baseRect.Width < baseRect.Height) { // return vertical capsule diameter = baseRect.Width; SizeF sizeF = new SizeF(diameter, diameter); arc = new RectangleF(baseRect.Location, sizeF); path.AddArc(arc, 180, 180); arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 180); } else { // return circle path.AddEllipse(baseRect); } } finally { path.CloseFigure(); } return(path); }
protected GraphicsPath GetGraphicsPath1(Rectangle rect) { GraphicsPath ClientPath = new System.Drawing.Drawing2D.GraphicsPath(); if (rect.Width <= 0) { rect.Width = 1; } if (rect.Height <= 0) { rect.Height = 1; } ClientPath.AddArc(rect.Left, rect.Top, rect.Height, rect.Height, 190f, 80f); ClientPath.AddArc(rect.Right - rect.Height, rect.Top, rect.Height, rect.Height, 270f, 80f); ClientPath.CloseFigure(); return(ClientPath); }
public static GraphicsPath Convert(Path2D path) { GdiPath gdiPath = new GdiPath(FillMode.Winding); foreach (Figure2D figure in path.Figures) { gdiPath.StartFigure(); gdiPath.AddLines(Convert(figure.Points)); if (figure.IsClosed) { gdiPath.CloseFigure(); } } return(gdiPath); }
public static SD2D.GraphicsPath RoundRect(RectangleF rectangle, float roundRadius) { var path = new SD2D.GraphicsPath(); roundRadius = Math.Min(roundRadius, Math.Min(rectangle.Width / 2, rectangle.Height / 2)); if (roundRadius <= 1) { path.AddRectangle(rectangle.ToSystemDrawingObject()); return(path); } RectangleF innerRect = RectangleF.Inflate(rectangle, -roundRadius, -roundRadius); path.StartFigure(); path.AddArc(RoundBounds(innerRect.Right - 1, innerRect.Bottom - 1, roundRadius), 0, 90); path.AddArc(RoundBounds(innerRect.Left, innerRect.Bottom - 1, roundRadius), 90, 90); path.AddArc(RoundBounds(innerRect.Left, innerRect.Top, roundRadius), 180, 90); path.AddArc(RoundBounds(innerRect.Right - 1, innerRect.Top, roundRadius), 270, 90); path.CloseFigure(); return(path); }
public static System.Drawing.Drawing2D.GraphicsPath Create(Rectangle bounds, int topoffset, int bottomoffset, int shrink) { System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath(); p.StartFigure(); //____ p.AddLine(bounds.X + topoffset + shrink, bounds.Y + shrink, bounds.Width - bottomoffset - shrink, bounds.Y + shrink); // \ p.AddLine(bounds.Width - bottomoffset - shrink, bounds.Y + shrink, bounds.Width - shrink, bounds.Y + bottomoffset + shrink); // | p.AddLine(bounds.Width - shrink, bounds.Y + bottomoffset + shrink, bounds.Width - topoffset - shrink, bounds.Height - shrink); // / p.AddLine(bounds.Width - topoffset - shrink, bounds.Height - shrink, bounds.X + bottomoffset + shrink, bounds.Height - shrink); //____ p.AddLine(bounds.X + bottomoffset + shrink, bounds.Height - shrink, bounds.X + shrink, bounds.Height - bottomoffset - shrink); // \ p.AddLine(bounds.X + shrink, bounds.Height - bottomoffset - shrink, bounds.X + topoffset + shrink, bounds.Y + shrink); p.CloseFigure(); return(p); }
private void DrawRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius) { Point top = new Point((int)X, (int)Y); Point bottom = new Point((int)X, (int)(Y + height)); GPath = new GraphicsPath(); if (RoundedCorners) { GPath.AddLine(X + radius, Y, X + width - (radius * 2), Y); GPath.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); GPath.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2)); GPath.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); GPath.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height); GPath.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); GPath.AddLine(X, Y + height - (radius * 2), X, Y + radius); GPath.AddArc(X, Y, radius * 2, radius * 2, 180, 90); GPath.CloseFigure(); } else { GPath.AddRectangle(new Rectangle(top, new Size((int)width, (int)height))); } if (HasFocus) { g.FillPath(new LinearGradientBrush(top, bottom, FocusBackColor1, FocusBackColor2), GPath); } else { g.FillPath(new LinearGradientBrush(top, bottom, BackColor1, BackColor2), GPath); } g.DrawPath(p, GPath); // Increase size of GPath for hit-testing purposes GPath = new GraphicsPath(); top.Offset(-2, -2); GPath.AddRectangle(new Rectangle(top, new Size((int)width + 4, (int)height + 4))); }
internal static System.Drawing.Drawing2D.GraphicsPath CreateRoundRectPath(System.Drawing.Rectangle bounds, int radius, Skybound.VisualTips.Rendering.VisualTipRenderer.BorderCorners corners) { System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); if ((corners & Skybound.VisualTips.Rendering.VisualTipRenderer.BorderCorners.TopLeft) == 0) { graphicsPath.AddLine(bounds.X, bounds.Y, bounds.X, bounds.Y); } else { graphicsPath.AddArc(new System.Drawing.Rectangle(bounds.X, bounds.Y, radius, radius), 180.0F, 90.0F); } if ((corners & Skybound.VisualTips.Rendering.VisualTipRenderer.BorderCorners.TopRight) == 0) { graphicsPath.AddLine(bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Y); } else { graphicsPath.AddArc(new System.Drawing.Rectangle(bounds.Right - radius - 1, bounds.Y, radius, radius), 270.0F, 90.0F); } if ((corners & Skybound.VisualTips.Rendering.VisualTipRenderer.BorderCorners.BottomRight) == 0) { graphicsPath.AddLine(bounds.Right - 1, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1); } else { graphicsPath.AddArc(new System.Drawing.Rectangle(bounds.Right - radius - 1, bounds.Bottom - radius - 1, radius, radius), 0.0F, 90.0F); } if ((corners & Skybound.VisualTips.Rendering.VisualTipRenderer.BorderCorners.BottomLeft) == 0) { graphicsPath.AddLine(bounds.X, bounds.Bottom - 1, bounds.X, bounds.Bottom - 1); } else { graphicsPath.AddArc(new System.Drawing.Rectangle(bounds.X, bounds.Bottom - radius - 1, radius, radius), 90.0F, 90.0F); } graphicsPath.CloseFigure(); return(graphicsPath); }
/// <summary> /// Ends the path, optionally closing it. /// </summary> /// <param name="close">if set to <see langword="true" /> the path will be closed; otherwise it will be left open.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath End(bool close = true) { _pathGeometry?.CloseFigure(); return(this); }
public void CloseFigure() { Control.CloseFigure(); }
/// <summary> /// /// </summary> /// <param name="pg"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="scale"></param> /// <returns></returns> public static D2D.GraphicsPath ToGraphicsPath(this IPathGeometry pg, double dx, double dy, Func <double, float> scale) { var gp = new D2D.GraphicsPath { FillMode = pg.FillRule == FillRule.EvenOdd ? D2D.FillMode.Alternate : D2D.FillMode.Winding }; foreach (var pf in pg.Figures) { var startPoint = pf.StartPoint; foreach (var segment in pf.Segments) { if (segment is IArcSegment arcSegment) { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); // TODO: Convert WPF/SVG elliptical arc segment format to GDI+ bezier curves. //startPoint = arcSegment.Point; } else if (segment is ICubicBezierSegment cubicBezierSegment) { gp.AddBezier( scale(startPoint.X + dx), scale(startPoint.Y + dy), scale(cubicBezierSegment.Point1.X + dx), scale(cubicBezierSegment.Point1.Y + dy), scale(cubicBezierSegment.Point2.X + dx), scale(cubicBezierSegment.Point2.Y + dy), scale(cubicBezierSegment.Point3.X + dx), scale(cubicBezierSegment.Point3.Y + dy)); startPoint = cubicBezierSegment.Point3; } else if (segment is ILineSegment lineSegment) { gp.AddLine( scale(startPoint.X + dx), scale(startPoint.Y + dy), scale(lineSegment.Point.X + dx), scale(lineSegment.Point.Y + dy)); startPoint = lineSegment.Point; } else if (segment is IPolyCubicBezierSegment polyCubicBezierSegment) { if (polyCubicBezierSegment.Points.Length >= 3) { gp.AddBezier( scale(startPoint.X + dx), scale(startPoint.Y + dy), scale(polyCubicBezierSegment.Points[0].X + dx), scale(polyCubicBezierSegment.Points[0].Y + dy), scale(polyCubicBezierSegment.Points[1].X + dx), scale(polyCubicBezierSegment.Points[1].Y + dy), scale(polyCubicBezierSegment.Points[2].X + dx), scale(polyCubicBezierSegment.Points[2].Y + dy)); } if (polyCubicBezierSegment.Points.Length > 3 && polyCubicBezierSegment.Points.Length % 3 == 0) { for (int i = 3; i < polyCubicBezierSegment.Points.Length; i += 3) { gp.AddBezier( scale(polyCubicBezierSegment.Points[i - 1].X + dx), scale(polyCubicBezierSegment.Points[i - 1].Y + dy), scale(polyCubicBezierSegment.Points[i].X + dx), scale(polyCubicBezierSegment.Points[i].Y + dy), scale(polyCubicBezierSegment.Points[i + 1].X + dx), scale(polyCubicBezierSegment.Points[i + 1].Y + dy), scale(polyCubicBezierSegment.Points[i + 2].X + dx), scale(polyCubicBezierSegment.Points[i + 2].Y + dy)); } } startPoint = polyCubicBezierSegment.Points.Last(); } else if (segment is IPolyLineSegment polyLineSegment) { if (polyLineSegment.Points.Length >= 1) { gp.AddLine( scale(startPoint.X + dx), scale(startPoint.Y + dy), scale(polyLineSegment.Points[0].X + dx), scale(polyLineSegment.Points[0].Y + dy)); } if (polyLineSegment.Points.Length > 1) { for (int i = 1; i < polyLineSegment.Points.Length; i++) { gp.AddLine( scale(polyLineSegment.Points[i - 1].X + dx), scale(polyLineSegment.Points[i - 1].Y + dy), scale(polyLineSegment.Points[i].X + dx), scale(polyLineSegment.Points[i].Y + dy)); } } startPoint = polyLineSegment.Points.Last(); } else if (segment is IPolyQuadraticBezierSegment polyQuadraticSegment) { if (polyQuadraticSegment.Points.Length >= 2) { var p1 = startPoint; var p2 = polyQuadraticSegment.Points[0]; var p3 = polyQuadraticSegment.Points[1]; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); } if (polyQuadraticSegment.Points.Length > 2 && polyQuadraticSegment.Points.Length % 2 == 0) { for (int i = 3; i < polyQuadraticSegment.Points.Length; i += 3) { var p1 = polyQuadraticSegment.Points[i - 1]; var p2 = polyQuadraticSegment.Points[i]; var p3 = polyQuadraticSegment.Points[i + 1]; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); } } startPoint = polyQuadraticSegment.Points.Last(); } else if (segment is IQuadraticBezierSegment quadraticBezierSegment) { var p1 = startPoint; var p2 = quadraticBezierSegment.Point1; var p3 = quadraticBezierSegment.Point2; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); startPoint = quadraticBezierSegment.Point2; } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } if (pf.IsClosed) { gp.CloseFigure(); } else { gp.StartFigure(); } } return(gp); }
static public void PolyDraw( System.Drawing.Drawing2D.GraphicsPath pPath, POINT[] lppt, byte[] lpbTypes, int cCount) { int nIndex; POINT pptLastMoveTo = new POINT(); POINT pptPrev = new POINT(); bool bLastMoveToNull = true; // for each of the points we have... for (nIndex = 0; nIndex < cCount; nIndex++) { switch (lpbTypes[nIndex]) { case PT_MOVETO: if (bLastMoveToNull == false && nIndex > 0) { pPath.CloseFigure(); } pptLastMoveTo = lppt[nIndex]; bLastMoveToNull = false; pptPrev = lppt[nIndex]; break; case PT_LINETO | PT_CLOSEFIGURE: pPath.AddLine(pptPrev.X, pptPrev.Y, lppt[nIndex].X, lppt[nIndex].Y); pptPrev = lppt[nIndex]; if (bLastMoveToNull == false) { pPath.CloseFigure(); pptPrev = pptLastMoveTo; } bLastMoveToNull = true; break; case PT_LINETO: pPath.AddLine(pptPrev.X, pptPrev.Y, lppt[nIndex].X, lppt[nIndex].Y); pptPrev = lppt[nIndex]; break; case PT_BEZIERTO | PT_CLOSEFIGURE: //ASSERT(nIndex + 2 <= cCount); pPath.AddBezier( pptPrev.X, pptPrev.Y, lppt[nIndex].X, lppt[nIndex].Y, lppt[nIndex + 1].X, lppt[nIndex + 1].Y, lppt[nIndex + 2].X, lppt[nIndex + 2].Y); nIndex += 2; pptPrev = lppt[nIndex]; if (bLastMoveToNull == false) { pPath.CloseFigure(); pptPrev = pptLastMoveTo; } bLastMoveToNull = true; break; case PT_BEZIERTO: //ASSERT(nIndex + 2 <= cCount); pPath.AddBezier( pptPrev.X, pptPrev.Y, lppt[nIndex].X, lppt[nIndex].Y, lppt[nIndex + 1].X, lppt[nIndex + 1].Y, lppt[nIndex + 2].X, lppt[nIndex + 2].Y); nIndex += 2; pptPrev = lppt[nIndex]; break; } } // If the figure was never closed and should be, // close it now. if (bLastMoveToNull == false && nIndex > 1) { pPath.AddLine(pptPrev.X, pptPrev.Y, pptLastMoveTo.X, pptLastMoveTo.Y); //pPath->CloseFigure(); } }
private static GraphicsPath GetCutRect(RectangleF baseRect, float radius, Corner corner) { // if corner radius is less than or equal to zero, // return the original rectangle if (radius <= 0.0F) { GraphicsPath mPath = new GraphicsPath(); mPath.AddRectangle(baseRect); mPath.CloseFigure(); return(mPath); } // if the corner radius is greater than or equal to // half the width, or height (whichever is shorter) // then return a capsule instead of a lozenge //if (radius >= (System.Math.Min(baseRect.Width, baseRect.Height)) / 2.0) // return GetCapsule(baseRect); // create the arc for the rectangle sides and declare // a graphics path object for the drawing //float diameter = radius * 2.0F; //SizeF sizeF = new SizeF(diameter, diameter); //RectangleF arc = new RectangleF(baseRect.Location, sizeF); GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if ((corner & Corner.TopLeft) == Corner.TopLeft) { path.AddLine(new PointF(radius, baseRect.Y), new PointF(0, radius)); } else { path.AddLine(new PointF(baseRect.X, baseRect.Y), new PointF(radius, baseRect.Y)); path.AddLine(new PointF(baseRect.X, baseRect.Y), new PointF(baseRect.X, radius)); } //画多边形边 path.AddLine( new PointF(radius, baseRect.Y), new PointF(baseRect.Right - radius, baseRect.Y) ); // top right corner if ((corner & Corner.TopRight) == Corner.TopRight) { path.AddLine( new PointF(baseRect.Right - radius, baseRect.Y), new PointF(baseRect.Right, radius)); } else { path.AddLine(new PointF(baseRect.Right - radius, baseRect.Y), new PointF(baseRect.Right, baseRect.Y)); path.AddLine(new PointF(baseRect.Right, baseRect.Y), new PointF(baseRect.Right, radius)); } // bottom right arc if ((corner & Corner.BottomRight) == Corner.BottomRight) { path.AddLine( new PointF(baseRect.Right, baseRect.Bottom - radius), new PointF(baseRect.Right - radius, baseRect.Bottom)); } else { path.AddLine(new PointF(baseRect.Right, baseRect.Bottom - radius), new PointF(baseRect.Right, baseRect.Bottom)); path.AddLine(new PointF(baseRect.Right, baseRect.Bottom), new PointF(baseRect.Right - radius, baseRect.Bottom)); } path.AddLine( new PointF(baseRect.Right - radius, baseRect.Bottom), new PointF(radius, baseRect.Bottom)); if ((corner & Corner.BottomLeft) == Corner.BottomLeft) { path.AddLine( new PointF(radius, baseRect.Bottom), new PointF(0, baseRect.Bottom - radius)); } else { path.AddLine(new PointF(baseRect.Right - radius, baseRect.Bottom), new PointF(baseRect.X, baseRect.Bottom)); path.AddLine(new PointF(baseRect.X, baseRect.Bottom), new PointF(baseRect.X, baseRect.Bottom - radius)); } // bottom left arc path.AddLine( new PointF(baseRect.X, baseRect.Bottom - radius), new PointF(baseRect.X, radius)); if ((corner & Corner.TopLeft) != Corner.TopLeft) { path.AddLine(new PointF(baseRect.X, baseRect.Y), new PointF(baseRect.X, radius)); } path.CloseFigure(); return(path); }
public void MoveTo(MoveTo moveTo) { _path.CloseFigure(); _currentPoint.X = (float)moveTo.X; _currentPoint.Y = (float)moveTo.Y; }