public AddArc ( Rectangle rect, float start_angle, float sweep_angle ) : void | ||
rect | Rectangle | |
start_angle | float | |
sweep_angle | float | |
return | void |
// 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); } }
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); }
// 圆角代码 public GraphicsPath BuildPath() { // ----------------------------------------------------------------------------------------------- // 已经是.net提供给我们的最容易的改窗体的属性了(以前要自己调API) System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath(); int x = this.BorderWidth; //(int)Math.Ceiling((this.BorderWidth - 1) / 2.0); int y = this.BorderWidth; //(int)Math.Ceiling((this.BorderWidth - 1) / 2.0); int thisWidth = this.Width - 2 * this.BorderWidth - 1; int thisHeight = this.Height - 2 * this.BorderWidth - 1; int angle = _radius; if (angle > 0) { System.Drawing.Graphics g = CreateGraphics(); oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角 oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角 oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角 oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角 oPath.CloseAllFigures(); //this.Region = new System.Drawing.Region(oPath); } // ----------------------------------------------------------------------------------------------- else { oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端 oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边 oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边 oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边 oPath.CloseAllFigures(); //this.Region = new System.Drawing.Region(oPath); } return(oPath); }
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(); }
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 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 override void RenderObject(Graphics g, DrawContext dcxt) { GraphicsPath path = new GraphicsPath(); foreach (Object ch in pathes) { if (ch is VectorPathLine) { VectorPathLine vpl = (VectorPathLine)ch; path.AddLine(dcxt.X_V2S(vpl.x1), dcxt.Y_V2S(vpl.y1), dcxt.X_V2S(vpl.x2), dcxt.Y_V2S(vpl.y2)); } else if (ch is VectorPathArc) { VectorPathArc vpa = (VectorPathArc)ch; path.AddArc(dcxt.X_V2S(vpa.x - vpa.w / 2), dcxt.Y_V2S(vpa.y - vpa.h/2), dcxt.W_V2S(vpa.w), dcxt.H_V2S(vpa.h), vpa.startagl, vpa.sweepagl); } else if (ch is VectorPathPie) { VectorPathPie vpp = (VectorPathPie)ch; path.AddArc(dcxt.X_V2S(vpp.x - vpp.w / 2), dcxt.Y_V2S(vpp.y - vpp.h/2), dcxt.W_V2S(vpp.w), dcxt.H_V2S(vpp.h), vpp.startagl, vpp.sweepagl); } } if (fill) g.FillPath(BrushWhenCxt(dcxt).Brush, path); else g.DrawPath(PenWhenCxt(dcxt).Pen, 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 GraphicsPath CreateCompleteTabPath(Rectangle r) { GraphicsPath path = new GraphicsPath(); int corner = 6; int rightOffset = 1; path.AddLine( r.Left, r.Bottom, r.Left, r.Top + corner); path.AddArc( new Rectangle( r.Left, r.Top, corner, corner), 180, 90); path.AddLine( r.Left + corner, r.Top, r.Right - corner - rightOffset, r.Top); path.AddArc( new Rectangle( r.Right - corner - rightOffset, r.Top, corner, corner), -90, 90); path.AddLine( r.Right - rightOffset, r.Top + corner, r.Right - rightOffset, r.Bottom); path.CloseFigure(); return path; }
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 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 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; }
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 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(); }
/// <summary> /// Draws a rounded rectangle on a bitmap /// </summary> /// <param name="Image">Image to draw on</param> /// <param name="BoxColor">The color that the box should be</param> /// <param name="XPosition">The upper right corner's x position</param> /// <param name="YPosition">The upper right corner's y position</param> /// <param name="Height">Height of the box</param> /// <param name="Width">Width of the box</param> /// <param name="CornerRadius">Radius of the corners</param> /// <returns>The bitmap with the rounded box on it</returns> public static Bitmap DrawRoundedRectangle(Bitmap Image, Color BoxColor, int XPosition, int YPosition, int Height, int Width, int CornerRadius) { Bitmap NewBitmap = new Bitmap(Image, Image.Width, Image.Height); using (Graphics NewGraphics = Graphics.FromImage(NewBitmap)) { using (Pen BoxPen = new Pen(BoxColor)) { using (GraphicsPath 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); } } } return NewBitmap; }
public override void AddTabBorder(System.Drawing.Drawing2D.GraphicsPath path, System.Drawing.Rectangle tabBounds) { switch (this._TabControl.Alignment) { case TabAlignment.Top: path.AddLine(tabBounds.X, tabBounds.Bottom, tabBounds.X + tabBounds.Height - 4, tabBounds.Y + 2); path.AddLine(tabBounds.X + tabBounds.Height, tabBounds.Y, tabBounds.Right - 3, tabBounds.Y); path.AddArc(tabBounds.Right - 6, tabBounds.Y, 6, 6, 270, 90); path.AddLine(tabBounds.Right, tabBounds.Y + 3, tabBounds.Right, tabBounds.Bottom); break; case TabAlignment.Bottom: path.AddLine(tabBounds.Right, tabBounds.Y, tabBounds.Right, tabBounds.Bottom - 3); path.AddArc(tabBounds.Right - 6, tabBounds.Bottom - 6, 6, 6, 0, 90); path.AddLine(tabBounds.Right - 3, tabBounds.Bottom, tabBounds.X + tabBounds.Height, tabBounds.Bottom); path.AddLine(tabBounds.X + tabBounds.Height - 4, tabBounds.Bottom - 2, tabBounds.X, tabBounds.Y); break; case TabAlignment.Left: path.AddLine(tabBounds.Right, tabBounds.Bottom, tabBounds.X + 3, tabBounds.Bottom); path.AddArc(tabBounds.X, tabBounds.Bottom - 6, 6, 6, 90, 90); path.AddLine(tabBounds.X, tabBounds.Bottom - 3, tabBounds.X, tabBounds.Y + tabBounds.Width); path.AddLine(tabBounds.X + 2, tabBounds.Y + tabBounds.Width - 4, tabBounds.Right, tabBounds.Y); break; case TabAlignment.Right: path.AddLine(tabBounds.X, tabBounds.Y, tabBounds.Right - 2, tabBounds.Y + tabBounds.Width - 4); path.AddLine(tabBounds.Right, tabBounds.Y + tabBounds.Width, tabBounds.Right, tabBounds.Bottom - 3); path.AddArc(tabBounds.Right - 6, tabBounds.Bottom - 6, 6, 6, 0, 90); path.AddLine(tabBounds.Right - 3, tabBounds.Bottom, tabBounds.X, tabBounds.Bottom); break; } }
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 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); } } }
private CustomLineCap GetClone(Pen pen, float size) { float endPoint; endPoint = pen.Width == 0 ? 1 : size / pen.Width; endPoint /= 2; if (endPoint <= 0) endPoint = 1e-3f; GraphicsPath hPath = new GraphicsPath(); var r = endPoint / (2 * Math.Sin(_designAngle * (Math.PI / 180))); var b = r - r * Math.Cos(_designAngle * (Math.PI / 180)); var h = endPoint / 2; // Create the outline for our custom end cap. hPath.AddArc( (float)(-r - h), (float)(-b), (float)(2 * r), (float)(2 * r), (float)(-90 - _designAngle), (float)(2 * _designAngle)); hPath.AddArc( (float)(h - r), (float)(b - 1.999999 * r), (float)(2 * r), (float)(2 * r), (float)(90 + _designAngle), (float)(-2 * _designAngle)); CustomLineCap clone = new CustomLineCap(null, hPath); // we set the stroke path only clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat); return clone; }
/// <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 static GraphicsPath CreateRoundedRectanglePath(RectangleF rect, float radius) { GraphicsPath path = new GraphicsPath(); if (rect.Width <= 0.0f || rect.Height <= 0.0f) return path; float x1 = rect.X; float x2 = rect.X + rect.Width; float y1 = rect.Y; float y2 = rect.Y + rect.Height; if (radius > rect.Width / 2) radius = rect.Width / 2; if (radius > rect.Height / 2) radius = rect.Width / 2; // Top left arc and top edge: if (radius > 0.0) path.AddArc(new RectangleF(x1, y1, radius * 2, radius * 2), 180, 90); path.AddLine(x1 + radius, y1, x2 - radius, y1); // Top right arc and right edge: if (radius > 0.0) path.AddArc(new RectangleF(x2 - radius * 2, y1, radius * 2, radius * 2), 270, 90); path.AddLine(x2, y1 + radius, x2, y2 - radius); // Bottom right arc and bottom edge: if (radius > 0.0) path.AddArc(new RectangleF(x2 - radius * 2, y2 - radius * 2, radius * 2, radius * 2), 0, 90); path.AddLine(x2 - radius, y2, x1 + radius, y2); // Bottom left arc and left edge: if (radius > 0.0) path.AddArc(new RectangleF(x1, y2 - radius * 2, radius * 2, radius * 2), 90, 90); path.AddLine(x1, y2 - radius, x1, y1 + radius); 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); }
/// <summary> /// 圆角代码 /// </summary> public void Round() { GraphicsPath oPath = new GraphicsPath(); const int x = 0; const int y = 0; int thisWidth = this.Width; int thisHeight = this.Height; int angle = _radius; if (angle > 0) { oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角 oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角 oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角 oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } else { oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端 oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边 oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边 oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } }
/// <summary> /// Create the Top tab path /// </summary> /// <returns>GraphicsPath</returns> private GraphicsPath TopTabPath() { Rectangle r = TabItem.DisplayRectangle; r.Width -= 1; // Allow for the TabStrip border if (TabItem.IsSelected == true) r.Height += 2; // Create the path GraphicsPath path = new GraphicsPath(); Rectangle ar = new Rectangle(r.X, r.Y, Radius, Radius); path.AddLine(r.X, r.Bottom, r.X, r.Top + Radius); path.AddArc(ar, 180, 90); path.AddLine(r.X + Radius, r.Top, r.Right - Radius, r.Top); ar.X = r.Right - Radius; path.AddArc(ar, 270, 90); path.AddLine(r.Right, r.Top + Radius, r.Right, r.Bottom); return (path); }
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; }
// 圆角代码 第一个参数是该元素的宽,第二个参数是元素的高,第三个参数是圆角半径 public Region Round(int width, int height, int _Radius) { System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath(); int x = 1; int y = 1; int thisWidth = width; int thisHeight = height; int angle = _Radius; if (angle > 0) { System.Drawing.Graphics g = CreateGraphics(); oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角 oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角 oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角 oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角 oPath.CloseAllFigures(); return(new System.Drawing.Region(oPath)); } // ----------------------------------------------------------------------------------------------- else { oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端 oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边 oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边 oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边 oPath.CloseAllFigures(); return(new System.Drawing.Region(oPath)); } }
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 }
// 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; }
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(); }
public static GraphicsPath AddRoundedRectangle(GraphicsPath path, Rectangle bounds, int c1, int c2, int c3, int c4) { if (c1 > 0) path.AddArc(bounds.Left, bounds.Top, c1, c1, 180, 90); else path.AddLine(bounds.Left, bounds.Top, bounds.Left, bounds.Top); if (c2 > 0) path.AddArc(bounds.Right - c2, bounds.Top, c2, c2, 270, 90); else path.AddLine(bounds.Right, bounds.Top, bounds.Right, bounds.Top); if (c3 > 0) path.AddArc(bounds.Right - c3, bounds.Bottom - c3, c3, c3, 0, 90); else path.AddLine(bounds.Right, bounds.Bottom, bounds.Right, bounds.Bottom); if (c4 > 0) path.AddArc(bounds.Left, bounds.Bottom - c4, c4, c4, 90, 90); else path.AddLine(bounds.Left, bounds.Bottom, bounds.Left, bounds.Bottom); path.CloseFigure(); return 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; }
public static void AddRoundedRectangle(GraphicsPath path, Rectangle bounds, int arcSize) { path.AddArc(new Rectangle(bounds.X, bounds.Y, arcSize, arcSize), 180, 90); path.AddArc(new Rectangle(bounds.X + bounds.Width - arcSize, bounds.Y, arcSize, arcSize), 270, 90); path.AddArc(new Rectangle(bounds.X + bounds.Width - arcSize, bounds.Y + bounds.Height - arcSize, arcSize, arcSize), 0, 90); path.AddArc(new Rectangle(bounds.X, bounds.Y + bounds.Height - arcSize, arcSize, arcSize), 90, 90); path.CloseFigure(); }
public void DrawArc(Rectangle re, GraphicsPath pa) { int _radiusX0Y0 = _radius, _radiusXFY0 = _radius, _radiusX0YF = _radius, _radiusXFYF = _radius; 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(); }
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); }
private GraphicsPath RoundRect(int x, int y, int width, int height, int radius, int lw) { var path = new GraphicsPath(); var num = radius * 2; path.AddArc(x + lw, y, num, num, 180f, 90f); path.AddArc(x + ((width - num) - lw), y, num, num, 270f, 90f); path.AddArc(x + ((width - num) - lw), y + ((height - num) - lw), num, num, 360f, 90f); path.AddArc(x + lw, y + ((height - num) - lw), num, num, 90f, 90f); path.CloseFigure(); return path; }
public GraphicsPath CreateRound(Rectangle r, int radius) { GraphicsPath CreateRoundPath = new GraphicsPath(FillMode.Winding); CreateRoundPath.AddArc(r.X, r.Y, radius, radius, 180F, 90F); CreateRoundPath.AddArc(r.Right - radius, r.Y, radius, radius, 270.0F, 90.0F); CreateRoundPath.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0.0F, 90.0F); CreateRoundPath.AddArc(r.X, r.Bottom - radius, radius, radius, 90.0F, 90.0F); CreateRoundPath.CloseFigure(); return CreateRoundPath; }
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); }
static GraphicsPath InitializeButtonShape() { GraphicsPath path = new GraphicsPath(); path.AddArc(0, 0, 3, 3, 180, 90); path.AddArc(17, 0, 3, 3, 270, 90); path.AddArc(17, 17, 3, 3, 0, 90); path.AddArc(0, 17, 3, 3, 90, 90); path.CloseFigure(); return path; }
private static void DrawRoundedRectangle(Graphics g, Rectangle r, int d, Pen p, Brush brush) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddArc(r.X, r.Y, d, d, 180, 90); gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90); gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90); gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90); gp.AddLine(r.X, r.Y + r.Height - d, r.X, r.Y + d / 2); g.FillRegion(brush, new Region(gp)); g.DrawPath(p, gp); }
public static void FillRoundedRectangle(this Graphics g, Brush brush, RectangleF bounds, float cornerRadius) { var lGraphicsPath = new GraphicsPath(); lGraphicsPath.AddArc(bounds.Left, bounds.Top, cornerRadius, cornerRadius, 180, 90); lGraphicsPath.AddArc(bounds.Right - cornerRadius - 1, bounds.Top, cornerRadius, cornerRadius, 270, 90); lGraphicsPath.AddArc(bounds.Right - cornerRadius - 1, bounds.Bottom - cornerRadius - 1, cornerRadius, cornerRadius, 0, 90); lGraphicsPath.AddArc(bounds.Left, bounds.Bottom - cornerRadius - 1, cornerRadius, cornerRadius, 90, 90); lGraphicsPath.CloseAllFigures(); g.FillPath(brush, lGraphicsPath); }
public static void DrawRoundedRectangle(Graphics g, Rectangle r, int d, Pen p) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddArc(r.X, r.Y, d, d, 180, 90); gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90); gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90); gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90); gp.AddLine(r.X, r.Y + r.Height - d, r.X, r.Y + d / 2); g.DrawPath(p, gp); }
private void RoundingButton(Button button) { Rectangle r = new Rectangle(0, 0, button.Width, button.Height); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); int d = 50; gp.AddArc(r.X, r.Y, d, d, 180, 90); gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90); gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90); gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90); button.Region = new Region(gp); }
private void RoundingPictureBox(PictureBox pictureBox1) { Rectangle r = new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); int d = 50; gp.AddArc(r.X, r.Y, d, d, 180, 90); gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90); gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90); gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90); pictureBox1.Region = new Region(gp); }
private static void SetRoundedShape(Control control, int radius) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddLine(radius, 0, control.Width - radius, 0); path.AddArc(control.Width - radius, 0, radius, radius, 270, 90); path.AddLine(control.Width, radius, control.Width, control.Height - radius); path.AddArc(control.Width - radius, control.Height - radius, radius, radius, 0, 90); path.AddLine(control.Width - radius, control.Height, radius, control.Height); path.AddArc(0, control.Height - radius, radius, radius, 90, 90); path.AddLine(0, control.Height - radius, 0, radius); path.AddArc(0, 0, radius, radius, 180, 90); control.Region = new Region(path); }
//rounded corner for header label private void makeCircleLabel(Label lbl) { Rectangle r = new Rectangle(0, 0, lbl.Width, lbl.Height); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); int d = 30; gp.AddArc(r.X, r.Y, d, d, 180, 90); gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90); gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90); gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90); lbl.Region = new Region(gp); }
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); }
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 void frmMain_Paint(object sender, PaintEventArgs e) { Rectangle Bounds = new Rectangle(0, 0, this.Width, this.Height); int CornerRadius = 20; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); path.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); path.CloseAllFigures(); this.Region = new Region(path); }
protected override void OnPaint(PaintEventArgs e) { float BorderThickness = 2; Size tSize = e.Graphics.MeasureString(this.Text, this.Font).ToSize(); int ArcWidth = this.RoundCorners * 2; int ArcHeight = this.RoundCorners * 2; int ArcX1 = 0; int ArcX2 = this.Width - (ArcWidth + 1); int ArcY1 = tSize.Height / 2; int ArcY2 = this.Height - (ArcHeight + 1); //Set Graphics smoothing mode to Anit-Alias-- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.GraphicsPath pathString = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackColor); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, BorderThickness); Rectangle r = new Rectangle(this.ClientRectangle.Left, this.ClientRectangle.Top, this.ClientRectangle.Width, this.ClientRectangle.Height); try { //Create Rounded Rectangle Path------ path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, 90); // Top Left path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, 90); //Top Right path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, 90); //Bottom Right path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, 90); //Bottom Left path.CloseAllFigures(); } catch (Exception ex) { } int offset = 1; pathString.AddLine(RoundCorners + offset, 0, RoundCorners + tSize.Width, 0); pathString.AddLine(RoundCorners + offset + tSize.Width, 0, RoundCorners + offset + tSize.Width, tSize.Height); pathString.AddLine(tSize.Width, tSize.Height, RoundCorners + offset, tSize.Height); pathString.AddLine(RoundCorners + offset, tSize.Height, RoundCorners + offset, 0); e.Graphics.FillPath(BackgroundBrush, path); e.Graphics.DrawPath(BorderPen, path); e.Graphics.FillPath(new SolidBrush(this.BackColor), pathString); e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), RoundCorners + offset, 0); }
private void UpdateRegion() { FindDiameter(); System.Drawing.Drawing2D.GraphicsPath FormRegion = new System.Drawing.Drawing2D.GraphicsPath(); FormRegion.AddArc(0, 0, m_fDiameter, m_fDiameter, -90, -180); FormRegion.AddLine(m_fRadius, this.Height - 1, this.Width - m_fDiameter, this.Height - 1); FormRegion.AddArc(this.Width, 0, m_fDiameter, m_fDiameter, 90, -180); FormRegion.AddLine(m_fRadius, 0, this.Width - m_fDiameter, 0); FormRegion.CloseAllFigures(); this.Region = new System.Drawing.Region(FormRegion); }
private void button1_Paint_1(object sender, PaintEventArgs e) { Rectangle Bounds = new Rectangle(0, 0, btnNext.Width, btnNext.Height); int CornerRadius = 50; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); path.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); path.CloseAllFigures(); btnNext.Region = new Region(path); btnPrevious.Region = new Region(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 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 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); }
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 static void AddSegmentToPath(ICurve seg, ref System.Drawing.Drawing2D.GraphicsPath p) { const float radiansToDegrees = (float)(180.0 / Math.PI); LineSegment line = seg as LineSegment; if (line != null) { p.AddLine(PointF(line.Start), PointF(line.End)); } else { CubicBezierSegment cb = seg as CubicBezierSegment; if (cb != null) { p.AddBezier(PointF(cb.B(0)), PointF(cb.B(1)), PointF(cb.B(2)), PointF(cb.B(3))); } else { Ellipse ellipse = seg as Ellipse; if (ellipse != null) { p.AddArc((float)(ellipse.Center.X - ellipse.AxisA.Length), (float)(ellipse.Center.Y - ellipse.AxisB.Length), (float)(2 * ellipse.AxisA.Length), (float)(2 * ellipse.AxisB.Length), (float)(ellipse.ParStart * radiansToDegrees), (float)((ellipse.ParEnd - ellipse.ParStart) * radiansToDegrees)); } } } }
// METHOD: DrawArc //------------------------------------------------------------------------ /// <summary> /// Draws an arc in a rectanglular area. /// </summary> /// /// <returns> /// None. /// </returns> /// /// <remarks> /// Draws an arc in the specified recangle /// </remarks> /// /// <!-- PARAMETERS --> /// <param name="graphics">The target graphics object to use.</param> /// <param name="pen">The pen object to use</param> /// <param name="Radius">The radius of the arc</param> /// <param name="Line1Start">The start location</param> /// <param name="Line1End">The end location</param> /// <param name="Line2Start">The start location</param> /// <param name="Line2End">The end location</param> /// <param name="StartAngle">The start angle</param> /// <param name="EndAngle">The end angle</param> //------------------------------------------------------------------------ public static void DrawArc(Graphics graphics, Pen pen, int Radius, Point Line1Start, Point Line1End, Point Line2Start, Point Line2End, float StartAngle, float EndAngle) { int doubleRadius = 2 * Radius; System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddArc(Line1End.X, Line1End.Y - Radius, doubleRadius, doubleRadius, StartAngle, EndAngle); graphics.DrawPath(pen, gp); }
private void timer3_Tick(object sender, EventArgs e) { panel3.Left = (this.Width - panel3.Width) / 2; panel3.Top = (this.Height - panel3.Height) / 2; Rectangle r = new Rectangle(0, 0, panel1.Width, panel1.Height); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); int d = 20; gp.AddArc(r.X, r.Y, d, d, 180, 90); gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90); gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90); gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90); panel1.Region = new Region(gp); }
private void pnlForm_Paint(object sender, PaintEventArgs e) { Rectangle Bounds = new Rectangle(0, 0, pnlForm.Width, pnlForm.Height); int CornerRadius = 20; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); path.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); path.CloseAllFigures(); pnlForm.Region = new Region(path); pnlPaiement.Region = new Region(path); pnlTaches.Region = new Region(path); pnlConsultation.Region = new Region(path); }
//#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); }
public MovieControl() { InitializeComponent(); Rectangle r = new Rectangle(0, 0, 182, 268); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); int d = 10; gp.AddArc(r.X, r.Y, d, d, 180, 90); gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90); gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90); gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90); pictureBox1.Region = new Region(gp); setViewStyleToolTip.SetToolTip(viewStyleBtn, "Grid View"); }