// 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 void Form1_Paint(object sender, PaintEventArgs e) { using (Graphics g = e.Graphics) { GraphicsPath path = new GraphicsPath(); path.AddLine(20, 20, 170, 20); path.AddLine(20, 20, 20, 100); // рисуем новую фигуру path.StartFigure(); path.AddLine(240, 140, 240, 50); path.AddLine(240, 140, 80, 140); path.AddRectangle(new Rectangle(30, 30, 200, 100)); // локальное преобразование траектории //Matrix X = new Matrix(); //X.RotateAt(45, new PointF(60.0f, 100.0f)); //path.Transform(X); // рисуем path Pen redPen = new Pen(Color.Red, 2); g.FillPath(new SolidBrush(Color.Bisque), path); g.DrawPath(redPen, 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); }
/// <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; } path.AddLine(rect.Left, rect.Top, rect.Left, rect.Bottom + 1); path.AddLine(rect.Left, rect.Top, rect.Right, rect.Top); path.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom + 1); path.AddLine(rect.Right, rect.Bottom + 1, rect.Left, rect.Bottom + 1); return(path); }
/// <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 void LineTo(float x, float y) { var point = new sd.PointF(x, y); Control.AddLine(position, point); position = point; }
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; }
protected virtual void RecalcBrushes(Rectangle position, Painter.State state) { if (_lastPosition == null || _lastPosition.Value != position || _lastState == null ||_lastState.Value != state) { _lastState = state; if (state == State.Hover) _borderPen = new Pen(Color.FromArgb(0x3c, 0x7f, 0xb1), 1); else if (state == State.Pressed) _borderPen = new Pen(Color.FromArgb(0x18, 0x59, 0x8a), 1); else _borderPen = new Pen(Color.FromArgb(0x9a, 0x9a, 0x9a), 1); _leftBounds = new Rectangle(position.X, position.Y, 8, position.Height); _leftBrush = CreateLeftBrush(_leftBounds, state); _middleBounds = new Rectangle(_leftBounds.Right, _leftBounds.Y, (int)((float)position.Width - 16), position.Height); _middleBrush = CreateMiddleBrush(_middleBounds, state); _rightBounds = new Rectangle(_middleBounds.Right, _leftBounds.Y, 8, position.Height); _rightBrush = CreateRightBrush(_rightBounds, state); _upperGradientPath = new GraphicsPath(); _upperGradientPath.AddLine(position.X + 8, position.Y + 1, position.X + 8, position.Y + 5); _upperGradientPath.AddLine(position.X + 8, position.Y + 5, _middleBounds.Right, position.Y + 5); _upperGradientPath.AddLine(_middleBounds.Right, position.Y + 5, _rightBounds.Right - 1, position.Y + 1); _upperGradientPath.CloseAllFigures(); _upperGradientRect = new Rectangle(position.X + 8, position.Y + 1, 10, 4); _upperGradientBrush = new LinearGradientBrush(_upperGradientRect, Color.FromArgb(0xed, 0xed, 0xed), Color.FromArgb(0xdd, 0xdd, 0xe0), LinearGradientMode.Vertical); _lastPosition = position; } }
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(); }
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; }
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 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 DrawTab(Graphics gr, Rectangle borderrect, int index, bool selected, Color color1, Color color2, Color coloroutline) { int additional = 0; // extra depth for fill if (selected) { additional = 1; borderrect.Height += borderrect.Y; // this one uses any height to get it bigger borderrect.Y = 0; } int xfar = borderrect.Right - 1; int yfar = borderrect.Bottom - 1; GraphicsPath border = new GraphicsPath(); border.AddLine(borderrect.X, yfar + additional, borderrect.X + shift, borderrect.Y); border.AddLine(borderrect.X + shift, borderrect.Y, xfar, borderrect.Y); border.AddLine(xfar, borderrect.Y, xfar + shift, yfar + additional); GraphicsPath fill = new GraphicsPath(); fill.AddLine(borderrect.X, yfar + additional + 1, borderrect.X + shift, borderrect.Y); fill.AddLine(borderrect.X + shift, borderrect.Y, xfar, borderrect.Y); fill.AddLine(xfar, borderrect.Y, xfar + shift, yfar + additional + 1); gr.SmoothingMode = SmoothingMode.Default; using (Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(borderrect, color1, color2, 90)) gr.FillPath(b, fill); gr.SmoothingMode = SmoothingMode.AntiAlias; using (Pen p = new Pen(coloroutline, 1.0F)) gr.DrawPath(p, border); }
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(); }
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); } }
public void DrawMarker(DragDropMarkerRendererEventArgs e) { Graphics g = e.Graphics; Rectangle bounds = e.Bounds; if (bounds.IsEmpty || _MarkerColor.IsEmpty) return; if (bounds.Width == AdvTree.DragInsertMarkSize) // Vertical insert mark { using (SolidBrush brush = new SolidBrush(_MarkerColor)) { using (Pen pen = new Pen(brush, 1)) { Point p = new Point(bounds.X + 4, bounds.Y); g.DrawLine(pen, p.X, p.Y, p.X, bounds.Bottom - 1); } using (GraphicsPath path = new GraphicsPath()) { path.AddLine(bounds.X, bounds.Y, bounds.X + 8, bounds.Y ); path.AddLine(bounds.X + 8, bounds.Y, bounds.X + 4, bounds.Y + 4); path.CloseAllFigures(); g.FillPath(brush, path); } using (GraphicsPath path = new GraphicsPath()) { path.AddLine(bounds.X, bounds.Bottom, bounds.X + 8, bounds.Bottom); path.AddLine(bounds.X + 8, bounds.Bottom, bounds.X + 4, bounds.Bottom - 4); path.CloseAllFigures(); g.FillPath(brush, path); } } } else { // Horizontal insert mark using (SolidBrush brush = new SolidBrush(_MarkerColor)) { using (Pen pen = new Pen(brush, 1)) { Point p = new Point(bounds.X, bounds.Y + 4); g.DrawLine(pen, p.X, p.Y, bounds.Right - 1, p.Y); } using (GraphicsPath path = new GraphicsPath()) { path.AddLine(bounds.X, bounds.Y, bounds.X, bounds.Y + 8); path.AddLine(bounds.X, bounds.Y + 8, bounds.X + 4, bounds.Y + 4); path.CloseAllFigures(); g.FillPath(brush, path); } using (GraphicsPath path = new GraphicsPath()) { path.AddLine(bounds.Right, bounds.Y, bounds.Right, bounds.Y + 8); path.AddLine(bounds.Right, bounds.Y + 8, bounds.Right - 4, bounds.Y + 4); path.CloseAllFigures(); g.FillPath(brush, path); } } } }
// 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 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; }
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 override void DrawTab(Graphics gr, Rectangle borderrect, int index, bool selected, Color color1, Color color2, Color coloroutline, TabAlignment alignment) { GraphicsPath border = new GraphicsPath(); GraphicsPath fill = new GraphicsPath(); int xfar = borderrect.Right - 1; int ybot = (alignment == TabAlignment.Bottom) ? (borderrect.Y) : (borderrect.Bottom - 1); int ytop = (alignment == TabAlignment.Bottom) ? (borderrect.Bottom-1-((selected)?0:2)) : (borderrect.Y - ((selected) ? 2 : 0)); border.AddLine(borderrect.X, ybot, borderrect.X + shift, ytop); border.AddLine(borderrect.X + shift, ytop, xfar, ytop); border.AddLine(xfar, ytop, xfar + shift, ybot); fill.AddLine(borderrect.X, ybot + 1, borderrect.X + shift, ytop); fill.AddLine(borderrect.X + shift, ytop, xfar, ytop); fill.AddLine(xfar, ytop, xfar + shift, ybot + 1); gr.SmoothingMode = SmoothingMode.Default; using (Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(borderrect, color1, color2, 90)) gr.FillPath(b, fill); gr.SmoothingMode = SmoothingMode.AntiAlias; using (Pen p = new Pen(coloroutline, 1.0F)) gr.DrawPath(p, border); }
// 圆角代码 第一个参数是该元素的宽,第二个参数是元素的高,第三个参数是圆角半径 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 GraphicsPath Path(SvgRenderer renderer) { if (_Path == null || this.IsPathDirty) { _Path = new GraphicsPath(); try { for (int i = 0; i < Points.Count; i += 2) { PointF endPoint = new PointF(Points[i].ToDeviceValue(renderer, UnitRenderingType.Horizontal, this), Points[i + 1].ToDeviceValue(renderer, UnitRenderingType.Vertical, this)); // TODO: Remove unrequired first line if (_Path.PointCount == 0) { _Path.AddLine(endPoint, endPoint); } else { _Path.AddLine(_Path.GetLastPoint(), endPoint); } } } catch (Exception exc) { Trace.TraceError("Error rendering points: " + exc.Message); } this.IsPathDirty = false; } return _Path; }
protected virtual GraphicsPath GetPath(int index) { Rectangle rect = base.GetTabRect(index); GraphicsPath gp = new GraphicsPath(); switch (base.Alignment) { case TabAlignment.Top: gp.AddLine(rect.Left + 1, rect.Bottom, rect.Left + 1, rect.Top); gp.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom); break; case TabAlignment.Bottom: gp.AddLine(rect.Left + 1, rect.Top - 1, rect.Left + 1, rect.Bottom); gp.AddLine(rect.Right, rect.Bottom, rect.Right, rect.Top - 1); break; case TabAlignment.Left: gp.AddLine(rect.Right + 1, rect.Top + 1, rect.Left + 1, rect.Top + 1); gp.AddLine(rect.Left + 1, rect.Bottom, rect.Right, rect.Bottom); break; case TabAlignment.Right: gp.AddLine(rect.Left - 1, rect.Top + 1, rect.Right - 2, rect.Top + 1); gp.AddLine(rect.Right - 2, rect.Bottom, rect.Left - 1, rect.Bottom); break; } return gp; }
/// <summary> /// Create the Top tab path /// </summary> /// <returns>GraphicsPath</returns> private GraphicsPath TopTabPath() { GraphicsPath path = new GraphicsPath(); Rectangle r = TabItem.DisplayRectangle; r.Width -= 1; r.Height -= 1; // Allow for the TabStrip border if (TabItem.IsSelected == true) r.Height += 2; // Create the path int n = TabStripItem.TabDisplay.TabSpacing; 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 - n - Radius, r.Top); ar.X = r.Right - n - Radius; path.AddArc(ar, 270, 90); path.AddLine(r.Right - n, r.Top + Radius, r.Right - n, r.Bottom); 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 override void DrawRegionRepresentation(Graphics gc, Render.RenderParameter r, Render.IDrawVisitor drawMethods, PointD mousePosition) { if (m_Param.Path.PointCount > 0) { GraphicsPath fill = new GraphicsPath(); RectangleF rect = m_Param.Path.GetBounds(); PointD refPt = (PointD)rect.Location + ((PointD)rect.Size.ToPointF()) / 2; // this will draw beyond the shape's location for (double i = -rect.Height; i < rect.Height; i++) { PointD orth = PointD.Orthogonal(m_Param.V); PointD pt1 = refPt + orth * i * drawMethods.Spacing(m_Param.C); PointD pt2 = pt1 + m_Param.V * rect.Width * rect.Height; PointD pt3 = pt1 - m_Param.V * rect.Width * rect.Height; PointD pt4 = refPt + m_Param.V * i * drawMethods.Spacing(m_Param.C); PointD pt5 = pt4 + orth * rect.Width * rect.Height; PointD pt6 = pt4 - orth * rect.Width * rect.Height; fill.StartFigure(); fill.AddLine((Point)pt2, (Point)pt3); fill.StartFigure(); fill.AddLine((Point)pt5, (Point)pt6); } GraphicsContainer c = gc.BeginContainer(); gc.SetClip( (Tools.Model.VectorPath) m_Param.Path); gc.DrawPath(r.RegionGuides, fill); gc.EndContainer(c); } }
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; }
protected override void WndProc(ref Message m) { base.WndProc(ref m); /*if (m.Msg == WM_PAINT) * { * Graphics g = Graphics.FromHwnd(Handle); * Rectangle bounds = new Rectangle(0, 0, Width, Height); * ControlPaint.DrawBorder(g, bounds, _borderColor, _borderStyle); * }*/ switch (m.Msg) { case 0xf: //Paint the background. Only the borders //will show up because the edit //box will be overlayed //Graphics g = Graphics.FromHwnd(Handle); Graphics g = this.CreateGraphics(); Rectangle bounds = new Rectangle(0, 0, Width, Height); ControlPaint.DrawBorder(g, bounds, _borderColor, _borderStyle); //Pen p = new Pen(Color.White, 2); //g.FillRectangle(BorderBrush, this.ClientRectangle); //Draw the background of the dropdown button Rectangle rect = new Rectangle(this.Width - 18, 0, 18, this.Height); g.FillRectangle(DropButtonBrush, rect); //Create the path for the arrow System.Drawing.Drawing2D.GraphicsPath pth = new System.Drawing.Drawing2D.GraphicsPath(); PointF TopLeft = new PointF(this.Width - 13, (this.Height - 5) / 2); PointF TopRight = new PointF(this.Width - 6, (this.Height - 5) / 2); PointF Bottom = new PointF(this.Width - 9, (this.Height + 2) / 2); pth.AddLine(TopLeft, TopRight); pth.AddLine(TopRight, Bottom); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //Determine the arrow's color. if (this.DroppedDown) { ArrowBrush = new SolidBrush(SystemColors.HighlightText); } else { ArrowBrush = new SolidBrush(SystemColors.ControlText); } //Draw the arrow g.FillPath(ArrowBrush, pth); g.Dispose(); break; } }
static GraphSymbol() { GraphicsPath graph = new GraphicsPath(); graph.AddLine(new Point(1000, 0), new Point(-1000, 0)); graph.AddLine(new Point(-1000, 0), new Point(0, 0)); graph.AddLine(new Point(0, 1000), new Point(0, -1000)); UserSymbols["Highlight"] = graph; }
private void RecomputeOutline() { m_outline = new GraphicsPath(); m_outline.AddLine(A, B); m_outline.AddLine(B, C); m_outline.AddLine(C, D); m_outline.CloseFigure(); }
public virtual void DrawCommandButton(NodeCommandPartRendererEventArgs info) { bool mouseOver = (info.Node.MouseOverNodePart == eMouseOverNodePart.Command); CommandColors c=new CommandColors(); if(mouseOver) { c.BackColor = info.MouseOverBackColor; c.BackColor2 = info.MouseOverBackColor2; c.BackColorGradientAngle = info.MouseOverBackColorGradientAngle; c.ForeColor = info.MouseOverForeColor; } else { c.BackColor = info.BackColor; c.BackColor2 = info.BackColor2; c.BackColorGradientAngle = info.BackColorGradientAngle; c.ForeColor = info.ForeColor; } Rectangle fillBounds = info.CommandPartBounds; fillBounds.Width--; fillBounds.Height--; Region oldRegion = info.Graphics.Clip.Clone() as Region; info.Graphics.SetClip(fillBounds,CombineMode.Intersect); if(c.BackColor2.IsEmpty) { if(!c.BackColor.IsEmpty) { using(SolidBrush brush=new SolidBrush(c.BackColor)) info.Graphics.FillRectangle(brush,fillBounds); } } else { using(LinearGradientBrush brush=DisplayHelp.CreateLinearGradientBrush(info.CommandPartBounds, c.BackColor, c.BackColor2, c.BackColorGradientAngle)) info.Graphics.FillRectangle(brush,fillBounds); } if(c.ForeColor.IsEmpty) return; int width=6; int height=3; GraphicsPath path=new GraphicsPath(); Point p=new Point(info.CommandPartBounds.X+(info.CommandPartBounds.Width-width)/2,info.CommandPartBounds.Y+(info.CommandPartBounds.Height-height)/2); path.AddLine(p.X, p.Y, p.X+width,p.Y); path.AddLine(p.X+width,p.Y,p.X+width/2,p.Y+height); path.AddLine(p.X, p.Y,p.X+width/2,p.Y+height); path.CloseAllFigures(); using(SolidBrush brush=new SolidBrush(c.ForeColor)) info.Graphics.FillPath(brush,path); path.Dispose(); info.Graphics.Clip = oldRegion; }
private void DrawSector(Graphics g, PointF center, PointF p1, PointF p2, Color innerColor, Color outerColor) { GraphicsPath pt = new GraphicsPath(); pt.AddLine(p1, center); pt.AddLine(center, p2); LinearGradientBrush lgb = new LinearGradientBrush( GetVertical(center, p1, p2) , center, outerColor, innerColor ); if (_triangularShape) lgb.SetBlendTriangularShape(0.5f); g.FillPath( lgb, pt ); }
public static GraphicsPath DrawPageUp(float X, float Y, float size) { GraphicsPath gp = new GraphicsPath(); gp.AddLine(X, Y + size, X + size, Y + size); gp.AddLine(X + size, Y + size, X + (size / 2), Y); gp.AddLine(X + (size / 2), Y, X, Y + size); gp.CloseFigure(); return gp; }
/// <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> /// 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 static GraphicsPath GetCloserButtonPath(Rectangle closerRect) { var closerPath = new GraphicsPath(); closerPath.AddLine(closerRect.X - 1, closerRect.Y - 2, closerRect.Right + 1, closerRect.Y - 2); closerPath.AddLine(closerRect.Right + 2, closerRect.Y - 1, closerRect.Right + 2, closerRect.Bottom + 1); closerPath.AddLine(closerRect.Right + 1, closerRect.Bottom + 2, closerRect.X - 1, closerRect.Bottom + 2); closerPath.AddLine(closerRect.X - 2, closerRect.Bottom + 1, closerRect.X - 2, closerRect.Y - 1); closerPath.CloseFigure(); return closerPath; }
/// <summary> /// Draws a drop-down glyph in the specified bounds. /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="state"></param> /// <param name="color"></param> static void DrawDropDownGlyph(Graphics g, Rectangle bounds, ComboBoxState state, Color?color = null) { if (state != ComboBoxState.Normal) { // standard dropdown button ComboBoxRenderer.DrawDropDownButton(g, bounds, state); } else if (Environment.OSVersion.Version >= new Version(10, 0)) { // windows 10 uses a slightly different chevron glyph int mX = bounds.X + (bounds.Width / 2); int mY = bounds.Y + (bounds.Height / 2); using (Pen pen = new Pen(color ?? Color.FromArgb(66, 66, 66), 1)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.DrawLine(pen, mX - 4, mY - 2, mX - 1, mY + 1); g.DrawLine(pen, mX + 3, mY - 2, mX - 1, mY + 1); g.DrawLine(pen, mX - 4, mY - 3, mX, mY + 1); g.DrawLine(pen, mX + 3, mY - 3, mX, mY + 1); } } else if (Environment.OSVersion.Version >= new Version(6, 2)) { // windows 8 uses a chevron glyph int mX = bounds.X + (bounds.Width / 2); int mY = bounds.Y + (bounds.Height / 2); using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath()) { path.AddLine(mX - 3, mY - 2, mX - 3, mY - 1); path.AddLine(mX - 3, mY - 1, mX, mY + 2); path.AddLine(mX, mY + 2, mX + 3, mY - 1); path.AddLine(mX + 3, mY - 1, mX + 3, mY - 2); using (Pen pen = new Pen(color ?? Color.FromArgb(66, 66, 66), 2)) { pen.StartCap = System.Drawing.Drawing2D.LineCap.Flat; pen.EndCap = System.Drawing.Drawing2D.LineCap.Flat; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.SetClip(new Rectangle(mX - 3, mY - 2, 7, 6)); g.DrawPath(pen, path); g.ResetClip(); } } } else { // windows vista and 7 use a triangle glyph g.FillPolygon(Brushes.Black, new Point[] { new Point(bounds.X + (bounds.Width / 2) - 3, bounds.Y + (bounds.Height / 2) - 1), new Point(bounds.X + (bounds.Width / 2) + 4, bounds.Y + (bounds.Height / 2) - 1), new Point(bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2) + 3) }); } }
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); }
protected override void WndProc(ref Message m) { base.WndProc(ref m); /*if (m.Msg == WM_PAINT) * { * Graphics g = Graphics.FromHwnd(Handle); * Rectangle bounds = new Rectangle(0, 0, Width, Height); * ControlPaint.DrawBorder(g, bounds, _borderColor, _borderStyle); * }*/ switch (m.Msg) { case 0xf: //Graphics g = Graphics.FromHwnd(Handle); Graphics g = this.CreateGraphics(); Rectangle bounds = new Rectangle(0, 0, Width, Height); ControlPaint.DrawBorder(g, bounds, _borderColor, _borderStyle); //Pen p = new Pen(Color.White, 2); g.FillRectangle(BorderBrush, this.ClientRectangle); Rectangle rect = new Rectangle(this.Width - 18, 0, 18, this.Height); g.FillRectangle(DropButtonBrush, rect); //g.FillPath(DropButtonBrush, RoundedRect(rect, 7)); System.Drawing.Drawing2D.GraphicsPath pth = new System.Drawing.Drawing2D.GraphicsPath(); PointF TopLeft = new PointF(this.Width - 13, (this.Height - 5) / 2); PointF TopRight = new PointF(this.Width - 6, (this.Height - 5) / 2); PointF Bottom = new PointF(this.Width - 9, (this.Height + 2) / 2); pth.AddLine(TopLeft, TopRight); pth.AddLine(TopRight, Bottom); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; /*if (this.DroppedDown) * { * ArrowBrush = new SolidBrush(SystemColors.HighlightText); * } * else * { * ArrowBrush = new SolidBrush(SystemColors.ControlText); * }*/ g.FillPath(ArrowBrush, pth); g.Dispose(); break; } }
private GraphicsPath GetPath(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; } /* if (index == 0)*/ { path.AddLine(rect.Left + 1, rect.Top + 1, rect.Left + 1, rect.Top + 1); path.AddLine(rect.Left + 1, rect.Top + 1, rect.Right, rect.Top + 1); path.AddLine(rect.Right, rect.Top + 1, rect.Right, rect.Bottom); path.AddLine(rect.Right, rect.Bottom, rect.Left + 1, rect.Bottom); } /*else * { * if (index == this.SelectedIndex) * { * path.AddLine(rect.Left - 1, rect.Top, rect.Left - 1, rect.Top); * path.AddLine(rect.Left - 1, rect.Top, rect.Right, rect.Top); * path.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom); * path.AddLine(rect.Right, rect.Bottom + 1, rect.Left - 1, rect.Bottom + 1); * } * else * { * path.AddLine(rect.Left - 1, rect.Top, rect.Left - 1, rect.Top); * path.AddLine(rect.Left - 1, rect.Top, rect.Right, rect.Top); * path.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom); * path.AddLine(rect.Right, rect.Bottom + 1, rect.Left - 1, rect.Bottom + 1); * } * }*/ return(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); }
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); }
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); }
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 drawArrow(Point startPoint) { Rectangle rect = new Rectangle(); int width = 60; rect.X = startPoint.X - width / 2; rect.Y = startPoint.Y - width / 2; rect.Width = width; rect.Height = width; Console.WriteLine("{0} [{1},{2}]", startPoint.ToString(), rect.X, rect.Y); this.BackColor = Color.Red; this.Opacity = 1; AdjustableArrowCap triangleCap = new AdjustableArrowCap(3, 2, true); Pen myPen = new Pen(Color.Red, 10); myPen.CustomEndCap = triangleCap; myPen.StartCap = LineCap.NoAnchor; System.Drawing.Drawing2D.GraphicsPath testPath = new System.Drawing.Drawing2D.GraphicsPath(); testPath.AddLine(new Point(startPoint.X + rect.Width, startPoint.Y + rect.Height), startPoint); testPath.Widen(myPen); Region region = new Region(rcScreen); region.Intersect(testPath); this.Region = region; }
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)); } } } }
/// <summary> /// Adds a line to the end of the path. /// </summary> /// <param name="to">The end point of the line.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddLine(Vector2 to) { PointF end = to.ToPointF(); _pathGeometry?.AddLine(_lastPoint, end); _lastPoint = end; return(this); }
/// <summary> /// Make rounded corners to bitmap /// </summary> /// <param name="a"></param> /// <param name="radius"></param> /// <returns></returns> public static Bitmap MakeRoundedCorners(Bitmap a, Int32 radius) { Bitmap bmp = (Bitmap)a.Clone(); Graphics g = Graphics.FromImage(bmp); System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); for (int i = 0; i < 4; i++) { System.Windows.Point[] cornerUpLeft = new System.Windows.Point[3]; cornerUpLeft[0].X = 0; cornerUpLeft[0].Y = 0; cornerUpLeft[1].X = radius; cornerUpLeft[1].Y = 0; cornerUpLeft[2].X = 0; cornerUpLeft[2].Y = radius; System.Drawing.Drawing2D.GraphicsPath pathCornerUpLeft = new System.Drawing.Drawing2D.GraphicsPath(); pathCornerUpLeft.AddArc((int)cornerUpLeft[0].X, (int)cornerUpLeft[0].Y, radius, radius, 180, 90); pathCornerUpLeft.AddLine((int)cornerUpLeft[0].X, (int)cornerUpLeft[0].Y, (int)cornerUpLeft[1].X, (int)cornerUpLeft[1].Y); pathCornerUpLeft.AddLine((int)cornerUpLeft[0].X, (int)cornerUpLeft[0].Y, (int)cornerUpLeft[2].X, (int)cornerUpLeft[2].Y); g.FillPath(brush, pathCornerUpLeft); pathCornerUpLeft.Dispose(); bmp.RotateFlip(RotateFlipType.Rotate90FlipNone); } brush.Dispose(); g.Dispose(); System.Drawing.Color backColor = bmp.GetPixel(0, 0); bmp.MakeTransparent(backColor); return(bmp); }
public void LineTo(LineTo lineTo) { float x = (float)lineTo.X; float y = (float)lineTo.Y; _path.AddLine(_currentPoint.X, _currentPoint.Y, x, y); _currentPoint.X = x; _currentPoint.Y = y; }
private System.Drawing.Drawing2D.GraphicsPath CreateGlarePath(System.Drawing.Rectangle bounds, int radius) { System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); if (radius == 0) { graphicsPath.AddLine(bounds.X, bounds.Y, bounds.Right - 1, bounds.Y); graphicsPath.AddLine(bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom - 1); } else { graphicsPath.AddLine(bounds.X + radius, bounds.Y, bounds.Right - radius - 1, bounds.Y); graphicsPath.AddArc(bounds.Right - radius - 1, bounds.Y, radius, radius, 270.0F, 90.0F); graphicsPath.AddLine(bounds.Right - 1, bounds.Y + radius, bounds.Right - 1, bounds.Bottom - radius); } graphicsPath.AddBezier(bounds.Right - 1, bounds.Bottom - 1, bounds.Right, bounds.Y + (bounds.Height / 2), bounds.X + (bounds.Width / 2), bounds.Y, bounds.X, bounds.Y); graphicsPath.CloseAllFigures(); return(graphicsPath); }
public static Bitmap DrawRoundedRectangle(Image im, Int32 Radius) { Bitmap Bmp = new Bitmap(im, im.Width, im.Height); Graphics G = Graphics.FromImage(Bmp); Brush brush = new System.Drawing.SolidBrush(Color.Red); for (int i = 0; i < 4; i++) { Point[] CornerUpLeft = new Point[3]; CornerUpLeft[0].X = 0; CornerUpLeft[0].Y = 0; CornerUpLeft[1].X = Radius; CornerUpLeft[1].Y = 0; CornerUpLeft[2].X = 0; CornerUpLeft[2].Y = Radius; System.Drawing.Drawing2D.GraphicsPath pathCornerUpLeft = new System.Drawing.Drawing2D.GraphicsPath(); pathCornerUpLeft.AddArc(CornerUpLeft[0].X, CornerUpLeft[0].Y, Radius, Radius, 180, 90); pathCornerUpLeft.AddLine(CornerUpLeft[0].X, CornerUpLeft[0].Y, CornerUpLeft[1].X, CornerUpLeft[1].Y); pathCornerUpLeft.AddLine(CornerUpLeft[0].X, CornerUpLeft[0].Y, CornerUpLeft[2].X, CornerUpLeft[2].Y); G.FillPath(brush, pathCornerUpLeft); pathCornerUpLeft.Dispose(); Bmp.RotateFlip(RotateFlipType.Rotate90FlipNone); } brush.Dispose(); G.Dispose(); Color backColor = Bmp.GetPixel(0, 0); Bmp.MakeTransparent(backColor); return(Bmp); }
public override void GetIsoline(System.Drawing.Drawing2D.GraphicsPath g, Logical3D r0, Logical3D r1) { double ax0, ax1, ay0, ay1; if (LogicalToLayerCoordinates(r0, out ax0, out ay0) && LogicalToLayerCoordinates(r1, out ax1, out ay1)) { // add a line when this is a radial ray if (((r0.RX == r1.RX) && !_isXYInterchanged) || ((r0.RY == r1.RY) && _isXYInterchanged)) { g.AddLine((float)ax0, (float)ay0, (float)ax1, (float)ay1); } // add an arc if this is a tangential ray else if (((r0.RY == r1.RY) && !_isXYInterchanged) || ((r0.RX == r1.RX) && _isXYInterchanged)) { double startAngle = 180 * Math.Atan2(_midY - ay0, ax0 - _midX) / Math.PI; double sweepAngle; if (_isXYInterchanged) { sweepAngle = (r1.RY - r0.RY) * 360; if (_isYreverse) { sweepAngle = -sweepAngle; } } else { sweepAngle = (r1.RX - r0.RX) * 360; if (_isXreverse) { sweepAngle = -sweepAngle; } } double r = Calc.RMath.Hypot(_midY - ay0, ax0 - _midX); if (r > 0) { g.AddArc((float)(_midX - r), (float)(_midY - r), (float)(2 * r), (float)(2 * r), (float)-startAngle, (float)-sweepAngle); } } else // if it is neither radial nor tangential { int points = _isXYInterchanged ? (int)(Math.Abs(r1.RY - r0.RY) * 360) : (int)(Math.Abs(r1.RX - r0.RX) * 360); points = Math.Max(1, Math.Min(points, 3600)); // in case there is a rotation more than one turn limit the number of points PointF[] pts = new PointF[points + 1]; for (int i = 0; i <= points; i++) { Logical3D r = new Logical3D(r0.RX + i * (r1.RX - r0.RX) / points, r0.RY + i * (r1.RY - r0.RY) / points); double ax, ay; LogicalToLayerCoordinates(r, out ax, out ay); pts[i] = new PointF((float)ax, (float)ay); } g.AddLines(pts); } } }
/// <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); }
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 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 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> /// Creates a GraphicsPath from two Int Arrays with a specific number of points. /// </summary> /// <param name="xPoints">Int Array to set the X points of the GraphicsPath</param> /// <param name="yPoints">Int Array to set the Y points of the GraphicsPath</param> /// <param name="pointsNumber">Number of points to add to the GraphicsPath</param> /// <returns>A new GraphicsPath</returns> public static System.Drawing.Drawing2D.GraphicsPath CreateGraphicsPath(int[] xPoints, int[] yPoints, int pointsNumber) { System.Drawing.Drawing2D.GraphicsPath tempGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); if (pointsNumber == 2) { tempGraphicsPath.AddLine(xPoints[0], yPoints[0], xPoints[1], yPoints[1]); } else { System.Drawing.Point[] tempPointArray = new System.Drawing.Point[pointsNumber]; for (int index = 0; index < pointsNumber; index++) { tempPointArray[index] = new System.Drawing.Point(xPoints[index], yPoints[index]); } tempGraphicsPath.AddPolygon(tempPointArray); } return(tempGraphicsPath); }