public static System.Drawing.Drawing2D.GraphicsPath CreateRoundedRectPath(float x, float y, float width, float height, float radius) { var xw = x + width; var yh = y + height; var xwr = xw - radius; var yhr = yh - radius; var xr = x + radius; var yr = y + radius; var r2 = radius * 2; var xwr2 = xw - r2; var yhr2 = yh - r2; var p = new System.Drawing.Drawing2D.GraphicsPath(); p.StartFigure(); p.AddArc(x, y, r2, r2, 180, 90); p.AddLine(xr, y, xwr, y); p.AddArc(xwr2, y, r2, r2, 270, 90); p.AddLine(xw, yr, xw, yhr); p.AddArc(xwr2, yhr2, r2, r2, 0, 90); p.AddLine(xwr, yh, xr, yh); p.AddArc(x, yhr2, r2, r2, 90, 90); p.AddLine(x, yhr, x, yr); p.CloseFigure(); return(p); }
// 圆角代码 public void Round(System.Drawing.Region region) { // ----------------------------------------------------------------------------------------------- // 已经是.net提供给我们的最容易的改窗体的属性了(以前要自己调API) System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath(); int x = 0; int y = 0; int thisWidth = this.Width; int thisHeight = this.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(); 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); } }
private System.Drawing.Drawing2D.GraphicsPath RoundRegion(Rectangle r) { //Scale the radius if it's too large to fit. int radius = CornerRadius; if (radius > (r.Width)) { radius = r.Width; } if (radius > (r.Height)) { radius = r.Height; } System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (radius <= 0) { path.AddRectangle(r); } else { path.AddArc(r.Left, r.Top, radius, radius, 180, 90); path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90); path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom); path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom); path.CloseFigure(); } return(path); }
private int _Radius = 50; // 圆角弧度 public void Round(System.Drawing.Region region) { System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath(); int x = 0; int y = 0; int thisWidth = this.Width; int thisHeight = this.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(); 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); } }
// 圆角代码 第一个参数是该元素的宽,第二个参数是元素的高,第三个参数是圆角半径 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)); } }
private void Grafico_Reload(object sender, EventArgs e) { _Timer.Stop(); //Dibuja los ejes _ejes.Reset(); _ejes.AddLine(_pxMargen, _pxMargen, _pxMargen, this.Height - _pxMargen); _ejes.AddLine(_pxMargen, this.Height - _pxMargen, this.Width - _pxMargen, this.Height - _pxMargen); _valores.Reset(); _valores.AddString(_MaxValueY.ToString(), System.Drawing.FontFamily.GenericSansSerif, (int)System.Drawing.FontStyle.Regular, (float)5, new System.Drawing.Point(0, _pxMargen), System.Drawing.StringFormat.GenericDefault); _valores.AddString(_MinValueY.ToString(), System.Drawing.FontFamily.GenericSansSerif, (int)System.Drawing.FontStyle.Regular, (float)5, new System.Drawing.Point(0, this.Height - _pxMargen), System.Drawing.StringFormat.GenericDefault); //Pepara la línea gráfica _Barras.Reset(); Point[] _vertices = new Point[((this.Width - _pxMargen) / _pxAnchoTick) + 3]; _vertices[0] = new Point(_pxMargen, this.Height - _pxMargen); _vertices[1] = _vertices[0]; int lastX = _pxMargen; for (int i = 2; i < _vertices.Length - 2; i++) { lastX = +_pxAnchoTick; _vertices[i] = new Point(lastX, this.Height - _pxMargen); } _vertices[_vertices.Length - 2] = new Point(this.Width, this.Height - _pxMargen); _vertices[_vertices.Length - 1] = _vertices[_vertices.Length - 2]; _Timer.Start(); }
protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case 0xf: Graphics g = this.CreateGraphics(); g.FillRectangle(BorderBrush, this.ClientRectangle); //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; //Draw the arrow g.FillPath(new SolidBrush(Color.White), pth); break; default: break; } }
// 圆角代码 public void Round(System.Drawing.Region region) { // ----------------------------------------------------------------------------------------------- // 已经是.net提供给我们的最容易的改窗体的属性了(以前要自己调API) System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath(); int x = 0; int y = 0; int thisWidth = this.Width; int thisHeight = this.Height; int angle = _Radius; if (angle > 0) { oPath.AddEllipse(x, y, this.Width, this.Height); // 左下角 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.Flatten(); // 左边 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } }
private void roundObject(Form obj) { System.Drawing.Drawing2D.GraphicsPath DGP = new System.Drawing.Drawing2D.GraphicsPath(); DGP.StartFigure(); //'top left corner DGP.AddArc(new Rectangle(0, 0, 40, 40), 180, 90); DGP.AddLine(40, 0, obj.Width - 40, 0); //'top right corner DGP.AddArc(new Rectangle(obj.Width - 40, 0, 40, 40), -90, 90); DGP.AddLine(obj.Width, 40, obj.Width, obj.Height - 40); //'buttom right corner DGP.AddArc(new Rectangle(obj.Width - 40, obj.Height - 40, 40, 40), 0, 90); DGP.AddLine(obj.Width - 40, obj.Height, 40, obj.Height); //'buttom left corner DGP.AddArc(new Rectangle(0, obj.Height - 40, 40, 40), 90, 90); DGP.CloseFigure(); obj.Region = new Region(DGP); }
private void DrawTextBox(ref Bitmap bmp) { Graphics g = Graphics.FromImage(bmp); int cRadius = bmp.Width * 5 / 400; int boxWidth = bmp.Width; int boxHeight = bmp.Height / 6; Rectangle rect = new Rectangle(cRadius / 2, cRadius / 2, boxWidth - cRadius, boxHeight - cRadius); // 指定图形路径, 有一系列 直线/曲线 组成 System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath(); myPath.StartFigure(); myPath.AddArc(new Rectangle(new Point(rect.X, rect.Y), new Size(2 * cRadius, 2 * cRadius)), 180, 90); myPath.AddLine(new Point(rect.X + cRadius, rect.Y), new Point(rect.Right - cRadius, rect.Y)); myPath.AddArc(new Rectangle(new Point(rect.Right - 2 * cRadius, rect.Y), new Size(2 * cRadius, 2 * cRadius)), 270, 90); myPath.AddLine(new Point(rect.Right, rect.Y + cRadius), new Point(rect.Right, rect.Bottom - cRadius)); myPath.AddArc(new Rectangle(new Point(rect.Right - 2 * cRadius, rect.Bottom - 2 * cRadius), new Size(2 * cRadius, 2 * cRadius)), 0, 90); myPath.AddLine(new Point(rect.Right - cRadius, rect.Bottom), new Point(rect.X + cRadius, rect.Bottom)); myPath.AddArc(new Rectangle(new Point(rect.X, rect.Bottom - 2 * cRadius), new Size(2 * cRadius, 2 * cRadius)), 90, 90); myPath.AddLine(new Point(rect.X, rect.Bottom - cRadius), new Point(rect.X, rect.Y + cRadius)); myPath.CloseFigure(); int opacity = 50; int alpha = (opacity * 255) / 100; g.FillPath(new SolidBrush(Color.FromArgb(alpha, Color.AliceBlue)), myPath); float fontSize = boxHeight * 25 / 80; int stringX = bmp.Width * 5 / 400; int stringY = (int)((boxHeight - fontSize / 72 * 96) / 3); g.DrawString(DateTime.Now.ToString("hh:mm:ss"), new Font("Segoe UI", fontSize), new SolidBrush(Color.Green), stringX, stringY); }
/// <summary> /// 角の丸い枠線を表すGraphicsPathを取得します /// </summary> /// <returns></returns> private System.Drawing.Drawing2D.GraphicsPath getGraphicsPath() { if (graphicsPath == null) { graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); graphicsPath.StartFigure(); int w = base.Width - 1; int h = base.Height - 1; // 上の横線 graphicsPath.AddLine(RADIUS, 0, w - RADIUS, 0); // 右上の角 graphicsPath.AddArc(w - DIAMETER, 0, DIAMETER, DIAMETER, 270, 90); // 右の縦線 graphicsPath.AddLine(w, RADIUS, w, h - RADIUS); // 右下の角 graphicsPath.AddArc(w - DIAMETER, h - DIAMETER, DIAMETER, DIAMETER, 0, 90); // 下の横線 graphicsPath.AddLine(w - RADIUS, h, RADIUS, h); // 左下の角 graphicsPath.AddArc(0, h - DIAMETER, DIAMETER, DIAMETER, 90, 90); // 左の縦線 graphicsPath.AddLine(0, h - RADIUS, 0, RADIUS); // 左上の角 graphicsPath.AddArc(0, 0, DIAMETER, DIAMETER, 180, 90); graphicsPath.CloseFigure(); } return(graphicsPath); }
public void UpdateGrid() { myGridPen = new Pen(Image.GridColour) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dash }; myGrid = new System.Drawing.Drawing2D.GraphicsPath(); int xDiff = (int)(Image.GridWidth * Image.ZoomScale); int yDiff = (int)(Image.GridHeight * Image.ZoomScale); if (xDiff > 1) { for (int x = Image.GridHorizontalOffset; x <= Image.Width; x += Image.GridWidth) { myGrid.StartFigure(); myGrid.AddLine(x * Image.ZoomScale, 0, x * Image.ZoomScale, myDisplaySize.Height); } } if (yDiff > 1) { for (int y = Image.GridVerticalOffset; y <= Image.Height; y += Image.GridHeight) { myGrid.StartFigure(); myGrid.AddLine(0, y * Image.ZoomScale, myDisplaySize.Width, y * Image.ZoomScale); } } Invalidate(); }
/// <summary> /// 划圆角边框 /// </summary> /// <param name="g">绘制的图形</param> /// <param name="p">颜色和粗细</param> /// <param name="X">绘制图形的初始X</param> /// <param name="Y">绘制图形的初始Y</param> /// <param name="width">绘制图形的宽度</param> /// <param name="height">绘制图形的高度</param> /// <param name="radius">绘制图形的弧度</param> public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.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(); }
/// <summary> /// 绘制圆角 /// </summary> /// <param name="g"></param> /// <param name="p"></param> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="radius"></param> public static void DrawRoundRect(Graphics g, Pen p, Brush brush,float X, float Y, float width, float height, float radius) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.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); g.FillPath(brush, gp); gp.Dispose(); }
private void pictureBox_MouseMove(object sender, MouseEventArgs e) { if (startDrawing) { if (Control.ModifierKeys == Keys.Control) { mousePath.Reset(); mousePath.AddLine(startPoint.X, startPoint.Y, startPoint.X, e.Y); measureWidth = false; //lblDistance.Text = roadWidth(rescalePoint(startPoint), rescalePoint(new Point(e.X, e.Y))).ToString("#0.00") + "m"; //lblDistance.Location = new Point(e.X + 5, e.Y - 14); pictureBox.Invalidate(); } else { mousePath.Reset(); mousePath.AddLine(startPoint.X, startPoint.Y, e.X, startPoint.Y); measureWidth = true; //lblDistance.Text = roadWidth(rescalePoint(startPoint), rescalePoint(new Point(e.X, startPoint.Y))).ToString("#0.00") + "m"; //lblDistance.Location = new Point(e.X + 5, startPoint.Y - 14); pictureBox.Invalidate(); } } if (isZoomOn) { _main.activatePbZoom(e.X, e.Y, pictureBox.Image); } }
protected override void WndProc(ref Message m) { try { base.WndProc(ref m); } catch { } if (m.Msg == WM_PAINT) { using (var g = Graphics.FromHwnd(Handle)) { using (var p = new Pen(BorderColorPrivate)) { g.DrawRectangle(p, 0, 0, Width - 1, Height - 1); g.DrawLine(p, Width - buttonWidth, 0, Width - buttonWidth, Height); } } } switch (m.Msg) { case 0xf: //Paint the background. Only the borders //will show up because the edit //box will be overlayed Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.White, 2); //Draw the background of the dropdown button Rectangle rect = new Rectangle(this.Width - 17, 1, 16, this.Height - 2); g.FillRectangle(new SolidBrush(this.BackColor), 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(ForeColor); } else { ArrowBrush = new SolidBrush(ForeColor); } //Draw the arrow g.FillPath(ArrowBrush, pth); break; default: break; // TODO: might not be correct. Was : Exit Select } }
void DrawPill(Graphics G, Pen P, Brush B, Brush B2, float x, float y, float width, float height, float fill, PillStyle style) { float H = height - width; float radius = width / 2.0f; switch (style) { case PillStyle.Bipolar: { if (fill > 0) { var FPath = new System.Drawing.Drawing2D.GraphicsPath(); // FPath.AddArc(x, y, width, width, 180, 180); FPath.AddLine(x + width, y + radius + 0.5f * (height - width), x + width, y + radius + (height - width - radius) * (fill * 0.5f + 0.5f)); // if (fill >= 0.9) // { FPath.AddArc(x, y + radius + (height - width - radius) * (fill * 0.5f + 0.5f), width, width, 0, 180); // } FPath.AddLine(x, y + radius + (height - width - radius) * (fill * 0.5f + 0.5f), x, y + radius + 0.5f * (height - width)); //G.FillPath(B, FPath); //x -= 50.0f; G.FillPath(B, FPath); } else { fill = 1 + fill; var FPath = new System.Drawing.Drawing2D.GraphicsPath(); FPath.AddArc(x, y + (fill * 0.5f) * (height - width), width, width, 180, 180); FPath.AddLine(x + width, y + (fill * 0.5f + 0.5f) * (height - width), x + width, y + radius + (height - width) * 0.5f); FPath.AddLine(x, y + radius + 0.5f * (height - width), x, y + radius + (height - width) * (fill * 0.5f + 0.5f)); G.FillPath(B2, FPath); } } break; case PillStyle.Positive: break; case PillStyle.Negative: break; } var Path = new System.Drawing.Drawing2D.GraphicsPath(); Path.AddArc(x, y, width, width, 180, 180); Path.AddLine(x + width, y + radius, x + width, y + height - radius); Path.AddArc(x, y + H, width, width, 0, 180); Path.AddLine(x, y + height - radius, x, y + radius); G.DrawPath(P, Path); }
private void Form1_Load(object sender, System.EventArgs e) { // Создаем некоторую область path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddLine(0, 0, 100, 100); path.AddLine(100, 100, 50, 20); path.AddLine(50, 20, 0, 0); }
private void rectangleShape2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { int mouseX = e.X + rectangleShape2.Left; int mouseY = e.Y + rectangleShape2.Top; // Add a line to the graphics path. mousePath.AddLine(mouseX, mouseY, mouseX, mouseY); }
/// <summary> /// Render plot view region of line chart component. /// </summary> /// <param name="dc">Platform no-associated drawing context.</param> protected override void OnPaint(DrawingContext dc) { var axisChart = base.Chart as AxisChart; if (axisChart == null) { return; } var ds = Chart.DataSource; var g = dc.Graphics; var clientRect = this.ClientBounds; var path = new System.Drawing.Drawing2D.GraphicsPath(); for (int r = 0; r < ds.SerialCount; r++) { var style = axisChart.DataSerialStyles[r]; var lastPoint = new System.Drawing.PointF(axisChart.PlotColumnPoints[0], axisChart.ZeroHeight); for (int c = 0; c < ds.CategoryCount; c++) { var pt = axisChart.PlotDataPoints[r][c]; System.Drawing.PointF point; if (pt.hasValue) { point = new System.Drawing.PointF(axisChart.PlotColumnPoints[c], axisChart.ZeroHeight - pt.value); } else { point = new System.Drawing.PointF(axisChart.PlotColumnPoints[c], axisChart.ZeroHeight); } path.AddLine(lastPoint, point); lastPoint = point; } var endPoint = new System.Drawing.PointF(axisChart.PlotColumnPoints[ds.CategoryCount - 1], axisChart.ZeroHeight); if (lastPoint != endPoint) { path.AddLine(lastPoint, endPoint); } path.CloseFigure(); g.FillPath(style.FillColor, path); path.Reset(); } path.Dispose(); }
/// <summary> /// takes in a parsed path and returns a list of points that can be used to draw the path /// </summary> /// <returns>The drawing points.</returns> /// <param name="segments">Segments.</param> public Vector2[] GetDrawingPoints(List <SvgPathSegment> segments, float flatness = 3) { var path = new System.Drawing.Drawing2D.GraphicsPath(); for (var j = 0; j < segments.Count; j++) { var segment = segments[j]; if (segment is SvgMoveToSegment) { path.StartFigure(); } else if (segment is SvgCubicCurveSegment) { var cubicSegment = segment as SvgCubicCurveSegment; path.AddBezier(ToDrawPoint(segment.Start), ToDrawPoint(cubicSegment.FirstCtrlPoint), ToDrawPoint(cubicSegment.SecondCtrlPoint), ToDrawPoint(segment.End)); } else if (segment is SvgClosePathSegment) { // important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure. if (path.PointCount > 0 && !path.PathPoints[0].Equals(path.PathPoints[path.PathPoints.Length - 1])) { var i = path.PathTypes.Length - 1; while (i >= 0 && path.PathTypes[i] > 0) { i--; } if (i < 0) { i = 0; } path.AddLine(path.PathPoints[path.PathPoints.Length - 1], path.PathPoints[i]); } path.CloseFigure(); } else if (segment is SvgLineSegment) { path.AddLine(ToDrawPoint(segment.Start), ToDrawPoint(segment.End)); } else if (segment is SvgQuadraticCurveSegment) { var quadSegment = segment as SvgQuadraticCurveSegment; path.AddBezier(ToDrawPoint(segment.Start), ToDrawPoint(quadSegment.FirstCtrlPoint), ToDrawPoint(quadSegment.SecondCtrlPoint), ToDrawPoint(segment.End)); } else { Debug.Warn("unknown type in getDrawingPoints"); } } path.Flatten(new System.Drawing.Drawing2D.Matrix(), flatness); return(System.Array.ConvertAll(path.PathPoints, i => new Vector2(i.X, i.Y))); }
static Pen PenArrow() { var tmpPen = new Pen(Color.Black); var hPath = new System.Drawing.Drawing2D.GraphicsPath(); hPath.AddLine(new Point(0, 0), new Point(-ARROW_WIDTH, -ARROW_WIDTH)); hPath.AddLine(new Point(0, 0), new Point(ARROW_WIDTH, -ARROW_WIDTH)); tmpPen.CustomEndCap = new System.Drawing.Drawing2D.CustomLineCap(null, hPath); return(tmpPen); }
/// <summary> /// Отрисовка фигуры /// </summary> public void Draw(PaintEventArgs ev) { dc = ev.Graphics; int dx, dy, mu = 5, ddx, ddy; int tx, ty; int x_x = (int)Math.Abs(x1 - x2) / 2; int y_y = (int)Math.Abs(y1 - y2) / 2; int rad = -nodes[0].Radius / 2; if (y2 < y1) { dy = -mu; ty = (int)y2; ddy = rad; } else { dy = 0; ty = (int)y1; ddy = -rad; } if (x2 < x1) { dx = -mu; tx = (int)x2; ddx = rad; } else { dx = 0; tx = (int)x1; ddx = -rad; } if (!directed) { Pen myPen = new Pen(color, mu); System.Drawing.Drawing2D.GraphicsPath hPath = new System.Drawing.Drawing2D.GraphicsPath(); hPath.AddLine(new Point(3, rad), new Point(0, -5)); //магические числа hPath.AddLine(new Point(-3, rad), new Point(0, -5)); System.Drawing.Drawing2D.CustomLineCap hCap = new System.Drawing.Drawing2D.CustomLineCap(null, hPath); myPen.CustomEndCap = hCap; dc.DrawLine(myPen, (int)x1 + dx + ddx, (int)y1 + dy + ddy, (int)x2 + dx - ddx, (int)y2 + dy - ddy); } else { dc.DrawLine(new Pen(color, mu), (int)x1 + dx + ddx, (int)y1 + dy + ddy, (int)x2 + dx - ddx, (int)y2 + dy - ddy); } Font font = new Font("Arial", 16, FontStyle.Regular); dc.DrawString(weight.ToString(), font, new SolidBrush(color2), (int)(tx + x_x), (int)(ty + y_y)); }
/// <summary> /// Overrides <see cref="CADability.Curve2D.GeneralCurve2D.AddToGraphicsPath (System.Drawing.Drawing2D.GraphicsPath, bool)"/> /// </summary> /// <param name="path"></param> /// <param name="forward"></param> public override void AddToGraphicsPath(System.Drawing.Drawing2D.GraphicsPath path, bool forward) { if (forward) { path.AddLine((float)startPoint.x, (float)startPoint.y, (float)endPoint.x, (float)endPoint.y); } else { path.AddLine((float)endPoint.x, (float)endPoint.y, (float)startPoint.x, (float)startPoint.y); } }
protected override void GeneratePath() { //Creates a triangle shape _Path = new System.Drawing.Drawing2D.GraphicsPath(); _Path.AddLine(Location.X + (Size.Width / 2), Location.Y, Location.X + Size.Width, Location.Y + Size.Height); _Path.AddLine(Location.X + Size.Width, Location.Y + Size.Height, Location.X, Location.Y + Size.Height); _Path.AddLine(Location.X, Location.Y + Size.Height, Location.X + (Size.Width / 2), Location.Y); }
private void CreateBody() { gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddArc(location.X, location.Y, 30.0F, 30.0F, 180, 180); gp.AddLine(new PointF(location.X + 30.0F, location.Y + 15.0F), new PointF(location.X + 30.0F, location.Y + 30.0F)); gp.AddLine(new PointF(location.X + 30.0F, location.Y + 30.0F), new PointF(location.X + 28.5F, location.Y + 30.0F)); gp.AddArc(location.X + 16.5F, location.Y + 17.0F, 12.0F, 26.0F, 180, 180); gp.AddLine(new PointF(location.X + 16.5F, location.Y + 30.0F), new PointF(location.X + 13.5F, location.Y + 30.0F)); gp.AddArc(location.X + 1.5F, location.Y + 17.0F, 12.0F, 26.0F, 180, 180); gp.AddLine(new PointF(location.X + 1.5F, location.Y + 30.0F), new PointF(location.X, location.Y + 30.0F)); //gp.AddLine(new PointF(location.X, location.Y + 30.0F), new PointF(location.X, location.Y + 15.0F)); }
static void DrawRoundedRectangle(Graphics g, Pen p, int x, int y, int w, int h, int rx, int ry) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(x, y, rx + rx, ry + ry, 180, 90); path.AddLine(x + rx, y, x + w - rx, y); path.AddArc(x + w - 2 * rx, y, 2 * rx, 2 * ry, 270, 90); path.AddLine(x + w, y + ry, x + w, y + h - ry); path.AddArc(x + w - 2 * rx, y + h - 2 * ry, rx + rx, ry + ry, 0, 91); path.AddLine(x + rx, y + h, x + w - rx, y + h); path.AddArc(x, y + h - 2 * ry, 2 * rx, 2 * ry, 90, 91); path.CloseFigure(); g.DrawPath(p, path); }
void DrawRoundRect(Graphics g, Brush b, int x, int y, int w, int h, int r) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(x, y, r + r, r + r, 180, 90); path.AddLine(x + r, y, x + w - r, y); path.AddArc(x + w - 2 * r, y, 2 * r, 2 * r, 270, 90); path.AddLine(x + w, y + r, x + w, y + h - r); path.AddArc(x + w - 2 * r, y + h - 2 * r, r + r, r + r, 0, 91); path.AddLine(x + r, y + h, x + w - r, y + h); path.AddArc(x, y + h - 2 * r, 2 * r, 2 * r, 90, 91); path.CloseFigure(); g.FillPath(b, path); }
//Rounded Controls 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 System.Drawing.Region(path); }
protected void DrawCombobox() { SuspendLayout(); Graphics g = this.CreateGraphics(); Pen p = new Pen(SkinManager.GetPrimaryTextColor(), 1); g.Clear(SkinManager.GetApplicationBackgroundColor()); // Draw the background of the dropdown button Rectangle rect = new Rectangle(this.Width - 15, 3, 12, this.Height - 6); 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.AntiAlias; // Determine the arrow's color. if (this.DroppedDown) { ArrowBrush = SkinManager.ColorScheme.AccentBrush; } else { ArrowBrush = SkinManager.GetPrimaryTextBrush(); } // Draw the arrow g.FillPath(ArrowBrush, pth); // Text if (DropDownStyle == ComboBoxStyle.DropDownList) { using (NativeTextRenderer NativeText = new NativeTextRenderer(g)) { NativeText.DrawTransparentText(Text, SkinManager.getLogFontByType(MaterialSkinManager.fontType.Body1), SkinManager.GetPrimaryTextColor(), ClientRectangle.Location, ClientRectangle.Size, NativeTextRenderer.TextAlignFlags.Left | NativeTextRenderer.TextAlignFlags.Middle); } } ResumeLayout(); }
/// <summary> /// The DrawCombobox /// </summary> protected void DrawCombobox() { SuspendLayout(); Graphics g = this.CreateGraphics(); Pen p = new Pen(SkinManager.GetPrimaryTextColor(), 1); BorderBrush = new SolidBrush(SkinManager.GetApplicationBackgroundColor()); g.Clear(SkinManager.GetApplicationBackgroundColor()); g.FillRectangle(BorderBrush, this.ClientRectangle); g.DrawRectangle(new Pen(SkinManager.GetApplicationBackgroundColor(), 1), this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1); // Draw the background of the dropdown button Rectangle rect = new Rectangle(this.Width - 15, 3, 12, this.Height - 6); 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 = SkinManager.ColorScheme.AccentBrush; } else { ArrowBrush = SkinManager.GetPrimaryTextBrush(); } // Draw the arrow g.FillPath(ArrowBrush, pth); if (DropDownStyle == ComboBoxStyle.DropDownList) { g.DrawString(this.Text, this.Font, SkinManager.GetPrimaryTextBrush(), ClientRectangle.X + 2, ClientRectangle.Y + 3); } ResumeLayout(); }
private void RePaint() { Graphics g = this.CreateGraphics(); //1A1E25 using (Pen p = new Pen(SkinManager.ComboBoxItemSelectFontColor)) using (Brush BorderBrush = new SolidBrush(SkinManager.ComboBoxItemSelectFontColor)) { g.FillRectangle(BorderBrush, this.ClientRectangle); } //CAD1E0 using (Pen boardPen = new Pen(SkinManager.FontColor)) g.DrawRectangle(boardPen, new Rectangle(1, 1, this.ClientRectangle.Width - 2, this.ClientRectangle.Height - 2)); //Draw the background of the dropdown button //Rectangle rect = new Rectangle(this.Width - 17, 0, 17, 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(Color.White); } else { ArrowBrush = new SolidBrush(Color.White); } //Draw the arrow g.FillPath(ArrowBrush, pth); SizeF size = g.MeasureString(this.Text, this.Font); //Font color : DBE2F1 using (SolidBrush sb = new SolidBrush(SkinManager.FontColor)) g.DrawString(this.Text, this.Font, sb, new PointF(0, (this.Height - size.Height) / 2f)); ArrowBrush.Dispose(); }
/// <summary> /// Method to curve our form border /// </summary> void curve_border() { System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath(); p.StartFigure(); p.AddArc(new System.Drawing.RectangleF(0, 0, 40, 40), 180, 90); p.AddLine(40, 0, this.Width - 40, 0); p.AddArc(new RectangleF(this.Width - 40, 0, 40, 40), -90, 90); p.AddLine(this.Width, 40, this.Width, this.Height - 40); p.AddArc(new RectangleF(this.Width - 40, this.Height - 40, 40, 40), 0, 90); p.AddLine(this.Width - 40, this.Height, 40, this.Height); p.AddArc(new Rectangle(0, this.Height - 40, 40, 40), 90, 90); p.CloseFigure(); this.Region = new Region(p); }
/// <summary> /// takes in a parsed path and returns a list of points that can be used to draw the path /// </summary> /// <returns>The drawing points.</returns> /// <param name="segments">Segments.</param> public Vector2[] getDrawingPoints( List<SvgPathSegment> segments, float flatness = 3 ) { var path = new System.Drawing.Drawing2D.GraphicsPath(); for( var j = 0; j < segments.Count; j++ ) { var segment = segments[j]; if( segment is SvgMoveToSegment ) { path.StartFigure(); } else if( segment is SvgCubicCurveSegment ) { var cubicSegment = segment as SvgCubicCurveSegment; path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( cubicSegment.firstCtrlPoint ), toDrawPoint( cubicSegment.secondCtrlPoint ), toDrawPoint( segment.end ) ); } else if( segment is SvgClosePathSegment ) { // important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure. if( path.PointCount > 0 && !path.PathPoints[0].Equals( path.PathPoints[path.PathPoints.Length - 1] ) ) { var i = path.PathTypes.Length - 1; while( i >= 0 && path.PathTypes[i] > 0 ) i--; if( i < 0 ) i = 0; path.AddLine( path.PathPoints[path.PathPoints.Length - 1], path.PathPoints[i] ); } path.CloseFigure(); } else if( segment is SvgLineSegment ) { path.AddLine( toDrawPoint( segment.start ), toDrawPoint( segment.end ) ); } else if( segment is SvgQuadraticCurveSegment ) { var quadSegment = segment as SvgQuadraticCurveSegment; path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( quadSegment.firstCtrlPoint ), toDrawPoint( quadSegment.secondCtrlPoint ), toDrawPoint( segment.end ) ); } else { Debug.warn( "unknown type in getDrawingPoints" ); } } path.Flatten( new System.Drawing.Drawing2D.Matrix(), flatness ); return System.Array.ConvertAll( path.PathPoints, i => new Vector2( i.X, i.Y ) ); }
private void DrawFilledPath(SeriesBase series, System.Drawing.Pen pen,System.Drawing.Brush brush) { var path = new System.Drawing.Drawing2D.GraphicsPath(); if (series is AreaSeries) { path.StartFigure(); AreaSeries areaSeries = series as AreaSeries; var points = areaSeries.AreaPoints; var pointCount = areaSeries.AreaPoints.Count; for (int i = 0; i < pointCount - 1; i++) { System.Drawing.PointF startPoint = points[i].AsDrawingPointF(); System.Drawing.PointF endPoint = points[i + 1].AsDrawingPointF(); path.AddLine(startPoint, endPoint); } path.CloseAllFigures(); switch (RenderingMode) { case RenderingMode.GDIRendering: GDIGraphics.FillPath(brush, path); break; case RenderingMode.Default: break; case RenderingMode.WritableBitmap: WritableBitmapGraphics.FillPath(brush, path); break; default: break; } } }
// Zeichnet das Rechteck mit abgerundeten Ecken der Termindetails public void DrawRoundRect(Graphics g, Pen p, float x, float y, float width, float height, float radius) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddLine(x + radius, y, x + width - (radius * 2), y); // Line gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); // Corner gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); // Line gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); // Line gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner gp.AddLine(x, y + height - (radius * 2), x, y + radius); // Line gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); // Corner gp.CloseFigure(); g.DrawPath(p, gp); gp.Dispose(); }
public static System.Drawing.Drawing2D.GraphicsPath DrawRoundRect(Rectangle r, int r1, int r2, int r3, int r4) { float x = r.X; float y = r.Y; float width = r.Width; float height = r.Height; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y); path.AddLine(x + r1, y, (x + width) - r2, y); path.AddBezier((x + width) - r2, y, x + width, y, x + width, y + r2, x + width, y + r2); path.AddLine((float)(x + width), (float)(y + r2), (float)(x + width), (float)((y + height) - r3)); path.AddBezier((float)(x + width), (float)((y + height) - r3), (float)(x + width), (float)(y + height), (float)((x + width) - r3), (float)(y + height), (float)((x + width) - r3), (float)(y + height)); path.AddLine((float)((x + width) - r3), (float)(y + height), (float)(x + r4), (float)(y + height)); path.AddBezier(x + r4, y + height, x, y + height, x, (y + height) - r4, x, (y + height) - r4); path.AddLine(x, (y + height) - r4, x, y + r1); return path; }
protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case 0xf: Graphics g = this.CreateGraphics(); g.FillRectangle(new SolidBrush(_colors.getBackgroundColor()), this.ClientRectangle); //Draw the background of the dropdown button Rectangle rect = new Rectangle(this.Width - 17, 0, 17, this.Height); g.FillRectangle(new SolidBrush(_colors.getBackgroundColor()), rect); // Draw the name of the selected item if (this.DropDownStyle == ComboBoxStyle.DropDownList) { g.DrawString(this.Text, this.Font, new SolidBrush(_colors.getForeColor()), 2, (this.Height / 2) - (this.Font.Size / 2)); } //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); Rectangle bounds = new Rectangle(0, 0, Width, Height); ControlPaint.DrawBorder(g, bounds, _colors.getBorderColor(), ButtonBorderStyle.Solid); if (this.DroppedDown) { ArrowBrush = new SolidBrush(_colors.getBorderColor()); } else { ArrowBrush = new SolidBrush(_colors.getForeColor()); } //Draw the arrow g.FillPath(ArrowBrush, pth); break; default: break; } }
//private static bool rectIntersectWithPolygon(RectangleF rect, Path path) //{ // System.Drawing.Drawing2D.GraphicsPath temp = new System.Drawing.Drawing2D.GraphicsPath(); // temp.Reset(); // List<PointF> points = default(List<PointF>); // foreach(object i in path.content) // { // if(i is Node) // { // Node node = (Node)i; // if(rect.Contains((float)node.lon, (float)node.lat)) // return true; // points.Add(new PointF((float)node.lon, (float)node.lat)); // } // } // temp.AddPolygon(points.ToArray()); // Region myRegion = new Region(); // myRegion.MakeEmpty(); // myRegion.Union(temp); // PointF tempPt = new PointF(); // tempPt.X = rect.X; // tempPt.Y = rect.Y; // if(pointInPolygon(tempPt, myRegion)) // return true; // tempPt.X = rect.X + rect.Width; // tempPt.Y = rect.Y; // if(pointInPolygon(tempPt, myRegion)) // return true; // tempPt.X = rect.X; // tempPt.Y = rect.Y + rect.Height; // if(pointInPolygon(tempPt, myRegion)) // return true; // tempPt.X = rect.X + rect.Width; // tempPt.Y = rect.Y + rect.Height; // if(pointInPolygon(tempPt, myRegion)) // return true; // return false; //} private static bool intersectPolygon(RectangleF rect, Path path) { System.Drawing.Drawing2D.GraphicsPath temp = new System.Drawing.Drawing2D.GraphicsPath(); temp.Reset(); // List<PointF> points = default(List<PointF>); List<PointF> points = new List<PointF>(); foreach (object i in path.content) { if (i is Node) { Node node = (Node)i; if (rect.Contains((float)node.lon, (float)node.lat)) return true; points.Add(new PointF((float)node.lon, (float)node.lat)); } } if (points.Count >= 3) { temp.AddPolygon(points.ToArray()); } else if (points.Count == 2) { temp.AddLine(points[0], points[1]); } Region myRegion = new Region(); myRegion.MakeEmpty(); myRegion.Union(temp); PointF tempPt = new PointF(); tempPt.X = rect.X; tempPt.Y = rect.Y; if (pointInPolygon(tempPt, myRegion)) return true; tempPt.X = rect.X + rect.Width; tempPt.Y = rect.Y; if (pointInPolygon(tempPt, myRegion)) return true; tempPt.X = rect.X; tempPt.Y = rect.Y + rect.Height; if (pointInPolygon(tempPt, myRegion)) return true; tempPt.X = rect.X + rect.Width; tempPt.Y = rect.Y + rect.Height; if (pointInPolygon(tempPt, myRegion)) return true; return false; }
/// <summary> /// Fill a closed path composed of several drawing operations /// </summary> /// <param name="canvas"></param> public void Fill(System.Drawing.Graphics canvas) { System.Drawing.Drawing2D.GraphicsPath path; path = new System.Drawing.Drawing2D.GraphicsPath(); for (int i = 0; i < m_drawings.Count; i++) { switch (m_drawings[i].Type) { case DrawingType.Line: { path.AddLine(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[1].x, m_drawings[i].Points[1].y); break; } case DrawingType.Arc: { double startAngle, endAngle; startAngle = System.Math.Atan2(m_drawings[i].Points[2].y - (m_drawings[i].Points[1].y + m_drawings[i].Points[0].y) / 2, m_drawings[i].Points[2].x - (m_drawings[i].Points[1].x + m_drawings[i].Points[0].x) / 2); if (startAngle < 0) { startAngle += System.Math.PI * 2; } startAngle = (startAngle / Math.PI) * 180; endAngle = System.Math.Atan2(m_drawings[i].Points[3].y - (m_drawings[i].Points[1].y + m_drawings[i].Points[0].y) / 2, m_drawings[i].Points[3].x - (m_drawings[i].Points[1].x + m_drawings[i].Points[0].x) / 2); if (endAngle < 0) { endAngle += System.Math.PI * 2; } endAngle = (endAngle / Math.PI) * 180; path.AddArc(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[1].x - m_drawings[i].Points[0].x, m_drawings[i].Points[1].y - m_drawings[i].Points[0].y, (float)startAngle, Math.Abs((float)(endAngle - startAngle))); break; } case DrawingType.Bezier: { path.AddBezier(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[2].x, m_drawings[i].Points[2].y, m_drawings[i].Points[3].x, m_drawings[i].Points[3].y, m_drawings[i].Points[1].x, m_drawings[i].Points[1].y); break; } } } canvas.FillPath(m_style.fillingStyle, path); }
private void PaintOffice2003(ItemPaintArgs pa) { // When on popup the Customize Item is painted same as in .NET style... if (BaseItem.IsOnPopup(this)) { PaintDotNet(pa); return; } Graphics g = pa.Graphics; Rectangle r = m_Rect; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (this.Orientation == eOrientation.Vertical) { // When on docked toolbar it has a special look... r.Y += 2; r.Height -= 1; r.X -= 2; r.Width += 2; if (pa.RightToLeft) { path.AddLine(r.Right, r.Y, r.Right - 2, r.Y + 2); path.AddLine(r.X + 2, r.Y + 2, r.X, r.Y); path.AddLine(r.X, r.Bottom - 2, r.X + 2, r.Bottom); path.AddLine(r.Right - 2, r.Bottom, r.Right, r.Bottom - 2); } else { path.AddLine(r.X, r.Y, r.X + 2, r.Y + 2); path.AddLine(r.Right - 2, r.Y + 2, r.Right, r.Y); path.AddLine(r.Right, r.Bottom - 2, r.Right - 2, r.Bottom); path.AddLine(r.X + 2, r.Bottom, r.X, r.Bottom - 2); } path.CloseAllFigures(); } else { // When on docked toolbar it has a special look... r.X += 2; r.Width -= 1; r.Y -= 2; r.Height += 3; if (pa.RightToLeft) { r.X -= 2; path.AddLine(r.Right, r.Y, r.Right - 2, r.Y + 2); path.AddLine(r.Right - 2, r.Bottom - 2, r.Right, r.Bottom); path.AddLine(r.X + 2, r.Bottom, r.X, r.Bottom - 2); path.AddLine(r.X, r.Y + 2, r.X + 2, r.Y); } else { path.AddLine(r.X, r.Y, r.X + 2, r.Y + 2); path.AddLine(r.X + 2, r.Bottom - 2, r.X, r.Bottom); path.AddLine(r.Right - 2, r.Bottom, r.Right, r.Bottom - 2); path.AddLine(r.Right, r.Y + 2, r.Right - 2, r.Y); } path.CloseAllFigures(); } System.Drawing.Drawing2D.SmoothingMode smooth = g.SmoothingMode; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (this.Expanded) DisplayHelp.FillPath(g, path, pa.Colors.ItemPressedBackground, pa.Colors.ItemPressedBackground2, pa.Colors.ItemPressedBackgroundGradientAngle); else if (m_MouseOver) DisplayHelp.FillPath(g, path, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle); else DisplayHelp.FillPath(g, path, pa.Colors.CustomizeBackground, pa.Colors.CustomizeBackground2, pa.Colors.CustomizeBackgroundGradientAngle); g.SmoothingMode = smooth; //using(Pen pen=new Pen(SystemColors.Window,1)) // g.DrawLine(pen,r.Left+(m_Rect.Width-4)/2+1,r.Bottom-11+1,r.Left+(m_Rect.Width-4)/2+4+1,r.Bottom-11+1); if (this.Orientation == eOrientation.Vertical) { // Draw Arrow Shade Point[] p = new Point[3]; p[0].X = r.Left + (m_Rect.Width - 4) / 2 + 2 + 1; p[0].Y = r.Bottom - 3 + 1; p[1].X = p[0].X - 2; p[1].Y = p[0].Y - 3; p[2].X = p[1].X + 5; p[2].Y = p[1].Y; using (SolidBrush brush = new SolidBrush(SystemColors.Window)) // SystemColors.HighlightText)) g.FillPolygon(brush, p); // Draw Arrow using (Pen pen = new Pen(pa.Colors.CustomizeText, 1)) g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2, r.Bottom - 9, r.Left + (m_Rect.Width - 4) / 2 + 4, r.Bottom - 9); p = new Point[3]; p[0].X = r.Left + (m_Rect.Width - 4) / 2 + 2; p[0].Y = r.Bottom - 3; p[1].X = p[0].X - 2; p[1].Y = p[0].Y - 3; p[2].X = p[1].X + 5; p[2].Y = p[1].Y; using (SolidBrush brush = new SolidBrush(pa.Colors.CustomizeText)) g.FillPolygon(brush, p); } else { // Draw Arrow Shade Point[] p = new Point[3]; p[0].X = r.Left + (m_Rect.Width - 4) / 2 + 2 + 1; p[0].Y = r.Bottom - 5 + 1; p[1].X = p[0].X - 2; p[1].Y = p[0].Y - 3; p[2].X = p[1].X + 5; p[2].Y = p[1].Y; using (SolidBrush brush = new SolidBrush(SystemColors.Window)) // SystemColors.HighlightText)) g.FillPolygon(brush, p); // Draw Arrow using (Pen pen = new Pen(pa.Colors.CustomizeText, 1)) g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2, r.Bottom - 11, r.Left + (m_Rect.Width - 4) / 2 + 4, r.Bottom - 11); p = new Point[3]; p[0].X = r.Left + (m_Rect.Width - 4) / 2 + 2; p[0].Y = r.Bottom - 5; p[1].X = p[0].X - 2; p[1].Y = p[0].Y - 3; p[2].X = p[1].X + 5; p[2].Y = p[1].Y; using (SolidBrush brush = new SolidBrush(pa.Colors.CustomizeText)) g.FillPolygon(brush, p); } }
public void UpdateGrid() { myGridPen = new Pen( Image.GridColour ) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dash }; myGrid = new System.Drawing.Drawing2D.GraphicsPath(); int xDiff = (int) ( Image.GridWidth * Image.ZoomScale ); int yDiff = (int) ( Image.GridHeight * Image.ZoomScale ); if ( xDiff > 1 ) { for ( int x = Image.GridHorizontalOffset; x <= Image.Width; x += Image.GridWidth ) { myGrid.StartFigure(); myGrid.AddLine( x * Image.ZoomScale, 0, x * Image.ZoomScale, myDisplaySize.Height ); } } if ( yDiff > 1 ) { for ( int y = Image.GridVerticalOffset; y <= Image.Height; y += Image.GridHeight ) { myGrid.StartFigure(); myGrid.AddLine( 0, y * Image.ZoomScale, myDisplaySize.Width, y * Image.ZoomScale ); } } Invalidate(); }
/// <summary> /// Converts this structure to a GraphicsPath object, used to draw to a Graphics device. /// Consider that you can create a Region with a GraphicsPath object using one of the Region constructor. /// </summary> /// <returns></returns> public System.Drawing.Drawing2D.GraphicsPath ToGraphicsPath() { if (mRectangle.IsEmpty) return new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (mRoundValue == 0) { //Remove 1 from height and width to draw the border in the right location //path.AddRectangle(new Rectangle(new Point(mRectangle.X - 1, mRectangle.Y - 1), mRectangle.Size)); path.AddRectangle(mRectangle); } else { int x = mRectangle.X; int y = mRectangle.Y; int lineShift = 0; int lineShiftX2 = 0; //Basically the RoundValue is a percentage of the line to curve, so I simply multiply it with the lower side (height or width) if (mRectangle.Height < mRectangle.Width) { lineShift = (int)((double)mRectangle.Height * mRoundValue); lineShiftX2 = lineShift * 2; } else { lineShift = (int)((double)mRectangle.Width * mRoundValue); lineShiftX2 = lineShift * 2; } //Top path.AddLine(lineShift + x, 0 + y, (mRectangle.Width - lineShift) + x, 0 + y); //Angle Top Right path.AddArc((mRectangle.Width - lineShiftX2) + x, 0 + y, lineShiftX2, lineShiftX2, 270, 90); //Right path.AddLine(mRectangle.Width + x, lineShift + y, mRectangle.Width + x, (mRectangle.Height - lineShift) + y); //Angle Bottom Right path.AddArc((mRectangle.Width - lineShiftX2) + x, (mRectangle.Height - lineShiftX2) + y, lineShiftX2, lineShiftX2, 0, 90); //Bottom path.AddLine((mRectangle.Width - lineShift) + x, mRectangle.Height + y, lineShift + x, mRectangle.Height + y); //Angle Bottom Left path.AddArc(0 + x, (mRectangle.Height - lineShiftX2) + y, lineShiftX2, lineShiftX2, 90, 90); //Left path.AddLine(0 + x, (mRectangle.Height - lineShift) + y, 0 + x, lineShift + y); //Angle Top Left path.AddArc(0 + x, 0 + y, lineShiftX2, lineShiftX2, 180, 90); } return path; }
/// <summary> /// Draws a segment filled. /// </summary> public void DrawFilled(C2DSegment Segment, Graphics graphics, Brush brush) { C2DRect Rect = new C2DRect(); int nStartAngle = 0; int nSweepAngle = 0; GetArcParameters(Segment.Arc, Rect, ref nStartAngle, ref nSweepAngle); if (nSweepAngle == 0) nSweepAngle = 1; int Width = (int)Rect.Width(); if (Width == 0) Width = 1; int Height = (int)Rect.Height(); if (Height == 0) Height = 1; System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y, Width, Height, nStartAngle, nSweepAngle); C2DPoint ptFrom = Segment.Arc.Line.GetPointFrom(); C2DPoint ptTo = Segment.Arc.Line.GetPointTo(); ScaleAndOffSet(ptFrom); ScaleAndOffSet(ptTo); gp.AddLine((int)ptTo.x, (int)ptTo.y, (int)ptFrom.x, (int)ptFrom.y); graphics.FillPath(brush, gp); }
/// <summary> /// Creates a GraphicsPath object and adds a line to it. /// </summary> /// <param name="x1">The x-coordinate of the starting point of the line.</param> /// <param name="y1">The y-coordinate of the starting point of the line.</param> /// <param name="x2">The x-coordinate of the endpoint of the line.</param> /// <param name="y2">The y-coordinate of the endpoint of the line.</param> /// <returns>Returns a GraphicsPath object containing the line.</returns> public static System.Drawing.Drawing2D.GraphicsPath CreateLine2DPath(float x1, float y1, float x2, float y2) { System.Drawing.Drawing2D.GraphicsPath linePath = new System.Drawing.Drawing2D.GraphicsPath(); linePath.AddLine(x1, y1, x2, y2); return linePath; }
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; } }
protected override void GeneratePath() { //Creates a triangle shape _Path = new System.Drawing.Drawing2D.GraphicsPath(); _Path.AddLine(Location.X + (Size.Width/2), Location.Y, Location.X + Size.Width, Location.Y+Size.Height); _Path.AddLine(Location.X + Size.Width, Location.Y+Size.Height, Location.X, Location.Y+Size.Height); _Path.AddLine(Location.X, Location.Y+Size.Height, Location.X + (Size.Width/2), Location.Y); }
private void DrawSeries(Graphics g, int _catsToCount, float _pixelsPerPoint, int axisIndex, float _widthPerCat, int x_offset, RectangleF _drawArea) { int columnscount = Series.Count(x => x.Type == cSeries.eType.Column); float columnwidth = ((_widthPerCat - 8) / columnscount) / _catSkipFactor[axisIndex]; int columnindex = 0; for (int k = 0; k < _seriesSorted.Count; k++) { if (_seriesSorted[k].Data != null && axisIndex == _seriesSorted[k].xAxis) { List<cSeries.Point> _serPoints = new List<cSeries.Point>(); for (int i = (int)x_offset; i < _seriesSorted[k].Data.Length && i < _catsToCount + x_offset; i++) { double _datavalue = 0; if (double.TryParse(_seriesSorted[k].Data[i], out _datavalue)) _serPoints.Add(new cSeries.Point( _drawArea.X + (_drawArea.Width / (float)_catsToCount) / 2 + (_drawArea.Width / (float)_catsToCount) * (i - x_offset), _drawArea.Y - ((float)_datavalue - _lowerLimit) * _pixelsPerPoint, _seriesSorted[k].Data[i])); else _serPoints.Add(null); } SolidBrush _serEllipseBrush = new SolidBrush(_seriesSorted[k].Color); int ar = _seriesSorted[k].Color.R; int ag = _seriesSorted[k].Color.G; int ab = _seriesSorted[k].Color.B; int aa = 100; SolidBrush _areaBrush = new SolidBrush(Color.FromArgb(aa, ar, ag, ab)); // Slow. Bitmap _texForBrush = new Bitmap(1, 1); TextureBrush _tbrush = new TextureBrush(_texForBrush); if (_seriesSorted[k].FillGradient && (_seriesSorted[k].Type == cSeries.eType.Area || _seriesSorted[k].Type == cSeries.eType.AreaSolid || _seriesSorted[k].Type == cSeries.eType.Column || _seriesSorted[k].Type == cSeries.eType.AreaSpline)) { _texForBrush = new Bitmap(1, (int)(_drawArea.Height)); for (int _tfbx = 0; _tfbx < _texForBrush.Width; _tfbx++) for (int _tfby = 0; _tfby < _texForBrush.Height; _tfby++) { int _tfba = 255 - (int)(((float)255 / (_texForBrush.Height)) * _tfby); _tfba = _tfba < 0 ? 0 : _tfba; _tfba = _tfba > 255 ? 255 : _tfba; _texForBrush.SetPixel(_tfbx, _tfby, Color.FromArgb(_tfba, _serEllipseBrush.Color.R, _serEllipseBrush.Color.G, _serEllipseBrush.Color.B)); } _tbrush = new TextureBrush(_texForBrush, System.Drawing.Drawing2D.WrapMode.Tile); _tbrush.TranslateTransform(_drawArea.X, _drawArea.Y); } Pen _serLinePen = new Pen(_seriesSorted[k].Color); _serLinePen.Width = 2 / _catSkipFactor[axisIndex]; if (_serLinePen.Width == 0) _serLinePen.Width = 1; for (int i = 0; i < _serPoints.Count; i++) { if (_serPoints[i] != null) { if (_serPoints[i].X > _pointBottomRight.X) continue; // dunno. switch (_seriesSorted[k].Type) { case cSeries.eType.Point: g.FillEllipse(_serEllipseBrush, _serPoints[i].X - 4 / _catSkipFactor[axisIndex], _serPoints[i].Y - 4 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex]); break; case cSeries.eType.PointLine: g.FillEllipse(_serEllipseBrush, _serPoints[i].X - 4 / _catSkipFactor[axisIndex], _serPoints[i].Y - 4 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex]); if (i + 1 < _serPoints.Count && _serPoints[i + 1] != null) { if (_serPoints[i + 1].X > _pointBottomRight.X) continue; // dunno. g.DrawLine(_serLinePen, _serPoints[i].X, _serPoints[i].Y, _serPoints[i + 1].X, _serPoints[i + 1].Y); } break; case cSeries.eType.Line: if (i + 1 < _serPoints.Count && _serPoints[i + 1] != null) { if (_serPoints[i + 1].X > _pointBottomRight.X) continue; // dunno. g.DrawLine(_serLinePen, _serPoints[i].X, _serPoints[i].Y, _serPoints[i + 1].X, _serPoints[i + 1].Y); } break; case cSeries.eType.LineShadowed: if (i + 1 < _serPoints.Count && _serPoints[i + 1] != null) { if (_serPoints[i + 1].X > _pointBottomRight.X) continue; // dunno. Pen pline = new Pen(Color.LightGray); pline.Width = 2 * _serScale[axisIndex]; g.DrawLine(pline, _serPoints[i].X + 1f * _serScale[axisIndex], _serPoints[i].Y + 1f * _serScale[axisIndex], _serPoints[i + 1].X + 1f * _serScale[axisIndex], _serPoints[i + 1].Y + 1f * _serScale[axisIndex]); g.DrawLine(_serLinePen, _serPoints[i].X, _serPoints[i].Y, _serPoints[i + 1].X, _serPoints[i + 1].Y); } break; case cSeries.eType.LineSolid: if (i + 1 < _serPoints.Count && i < _catsToCount) { if (_serPoints[i + 1] == null) g.FillEllipse(_serEllipseBrush, _serPoints[i].X - 4 / _catSkipFactor[axisIndex], _serPoints[i].Y - 4 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex]); else { if (_serPoints[i + 1].X > _pointBottomRight.X) continue; // dunno. float half_dis = (_serPoints[i + 1].X - _serPoints[i].X) / 2; g.DrawLine(_serLinePen, _serPoints[i].X - half_dis, _serPoints[i].Y, _serPoints[i].X + half_dis, _serPoints[i].Y); g.DrawLine(_serLinePen, _serPoints[i].X + half_dis, _serPoints[i].Y, _serPoints[i].X + half_dis, _serPoints[i + 1].Y); g.DrawLine(_serLinePen, _serPoints[i].X + half_dis, _serPoints[i + 1].Y, _serPoints[i + 1].X + half_dis, _serPoints[i + 1].Y); } } break; case cSeries.eType.Spline: { List<PointF> _curvePoints = new List<PointF>(); foreach (var p in _serPoints) if (p != null && p.X <= _pointBottomRight.X) _curvePoints.Add(new PointF(p.X, p.Y)); g.DrawCurve(_serLinePen, _curvePoints.ToArray()); i = _serPoints.Count; } break; case cSeries.eType.Column: if (!_seriesSorted[k].FillGradient) g.FillRectangle(_serEllipseBrush, _serPoints[i].X + (columnscount > 1 ? -columnwidth * columnscount / 2 + columnwidth * columnindex : -columnwidth / 2), _serPoints[i].Y, columnwidth, _drawArea.Y - _serPoints[i].Y); else g.FillRectangle(_tbrush, _serPoints[i].X + (columnscount > 1 ? -columnwidth * columnscount / 2 + columnwidth * columnindex : -columnwidth / 2), _serPoints[i].Y, columnwidth, _drawArea.Y - _serPoints[i].Y); if (_seriesSorted[k].Outline) g.DrawRectangle(_serLinePen, _serPoints[i].X + (columnscount > 1 ? -columnwidth * columnscount / 2 + columnwidth * columnindex : -columnwidth / 2), _serPoints[i].Y, columnwidth, _drawArea.Y - _serPoints[i].Y); //g.DrawString(_serPoints[i].Data, xAxis[axisIndex].CategoriesFont, Brushes.DarkGray, _serPoints[i].X, _serPoints[i].Y); break; case cSeries.eType.Area: //if (i == 0) // g.FillEllipse(_serEllipseBrush, _serPoints[i].X - 4 / _catSkipFactor[axisIndex], _serPoints[i].Y - 4 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex]); if (i + 1 < _serPoints.Count && _serPoints[i + 1] != null && i < _catsToCount) { if (_serPoints[i + 1].X > _pointBottomRight.X) continue; // dunno. List<PointF> _areaPoints = new List<PointF>(); _areaPoints.Add(new PointF(_serPoints[i].X, _serPoints[i].Y)); _areaPoints.Add(new PointF(_serPoints[i + 1].X, _serPoints[i + 1].Y)); _areaPoints.Add(new PointF(_serPoints[i + 1].X, _drawArea.Y)); _areaPoints.Add(new PointF(_serPoints[i].X, _drawArea.Y)); if (!_seriesSorted[k].FillGradient) g.FillPolygon(_areaBrush, _areaPoints.ToArray()); else g.FillPolygon(_tbrush, _areaPoints.ToArray()); if (_seriesSorted[k].Outline) g.DrawLine(_serLinePen, _serPoints[i].X, _serPoints[i].Y, _serPoints[i + 1].X, _serPoints[i + 1].Y); } //else // g.FillEllipse(_serEllipseBrush, _serPoints[i].X - 4 / _catSkipFactor[axisIndex], _serPoints[i].Y - 4 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex], 8 / _catSkipFactor[axisIndex]); break; case cSeries.eType.AreaSolid: if (i + 1 < _serPoints.Count && _serPoints[i + 1] != null && i < _catsToCount) { if (_serPoints[i + 1].X > _pointBottomRight.X) continue; // dunno. float half_dis = (_serPoints[i + 1].X - _serPoints[i].X) / 2; List<PointF> _areaPoints = new List<PointF>(); _areaPoints.Add(new PointF(_serPoints[i].X - (i == 0 ? half_dis : 0), _serPoints[i].Y)); _areaPoints.Add(new PointF(_serPoints[i].X + half_dis, _serPoints[i].Y)); _areaPoints.Add(new PointF(_serPoints[i].X + half_dis, _serPoints[i + 1].Y)); _areaPoints.Add(new PointF(_serPoints[i + 1].X + (i + 2 == _serPoints.Count ? half_dis : 0) + .05f, _serPoints[i + 1].Y)); _areaPoints.Add(new PointF(_serPoints[i + 1].X + (i + 2 == _serPoints.Count ? half_dis : 0) + .05f, _drawArea.Y)); _areaPoints.Add(new PointF(_serPoints[i].X - (i == 0 ? half_dis : 0), _drawArea.Y)); if (!_seriesSorted[k].FillGradient) g.FillPolygon(_areaBrush, _areaPoints.ToArray()); else g.FillPolygon(_tbrush, _areaPoints.ToArray()); if (_seriesSorted[k].Outline) { g.DrawLine(_serLinePen, _serPoints[i].X - (i == 0 ? half_dis : 0), _serPoints[i].Y, _serPoints[i].X + half_dis, _serPoints[i].Y); g.DrawLine(_serLinePen, _serPoints[i].X + half_dis, _serPoints[i].Y, _serPoints[i].X + half_dis, _serPoints[i + 1].Y); g.DrawLine(_serLinePen, _serPoints[i].X + half_dis, _serPoints[i + 1].Y, _serPoints[i + 1].X + (i + 2 == _serPoints.Count ? half_dis : 0), _serPoints[i + 1].Y); } } break; case cSeries.eType.AreaSpline: { List<PointF> _curvePoints = new List<PointF>(); foreach (var p in _serPoints) if (p != null && p.X <= _pointBottomRight.X) _curvePoints.Add(new PointF(p.X, p.Y)); i = _serPoints.Count; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddCurve(_curvePoints.ToArray()); if (_curvePoints.Count > 0) { PointF firstPoint = new PointF(_curvePoints[0].X, _curvePoints[0].Y); PointF lastPoint = new PointF(_curvePoints[_curvePoints.Count - 1].X, _curvePoints[_curvePoints.Count - 1].Y); path.AddLine(lastPoint.X, lastPoint.Y, lastPoint.X, _drawArea.Y); path.AddLine(lastPoint.X, _drawArea.Y, firstPoint.X, _drawArea.Y); path.AddLine(firstPoint.X, _drawArea.Y, firstPoint.X, firstPoint.Y); if (!_seriesSorted[k].FillGradient) g.FillPath(_areaBrush, path); else g.FillPath(_tbrush, path); if (_seriesSorted[k].Outline) g.DrawCurve(_serLinePen, _curvePoints.ToArray()); //g.DrawLine(_serLinePen, lastPoint.X, lastPoint.Y, lastPoint.X, _plotLowerPoint.Y); //g.DrawLine(_serLinePen, firstPoint.X, _plotLowerPoint.Y, firstPoint.X, firstPoint.Y); } } break; } } } if (_seriesSorted[k].Type == cSeries.eType.Column) columnindex++; } } }
public static void DrawRoundedRectangleOutlined(Graphics gfxObj, Pen penObj, float X, float Y, float RectWidth, float RectHeight, float CornerRadius) { RectWidth--; RectHeight--; System.Drawing.Drawing2D.GraphicsPath gfxPath = new System.Drawing.Drawing2D.GraphicsPath(); gfxPath.AddLine(X + CornerRadius, Y, X + RectWidth - (CornerRadius * 2), Y); gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y, CornerRadius * 2, CornerRadius * 2, 270, 90); gfxPath.AddLine(X + RectWidth, Y + CornerRadius, X + RectWidth, Y + RectHeight - (CornerRadius * 2)); gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 0, 90); gfxPath.AddLine(X + RectWidth - (CornerRadius * 2), Y + RectHeight, X + CornerRadius, Y + RectHeight); gfxPath.AddArc(X, Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 90, 90); gfxPath.AddLine(X, Y + RectHeight - (CornerRadius * 2), X, Y + CornerRadius); gfxPath.AddArc(X, Y, CornerRadius * 2, CornerRadius * 2, 180, 90); gfxPath.CloseFigure(); gfxObj.DrawPath(penObj, gfxPath); gfxPath.Dispose(); }
public static int drawer(OptsType opts, ArgsType args) { string[] commands = Regex.Split(Console.In.ReadToEnd(), @"\r?\n"); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); List<PointF> pts = new List<PointF>(); foreach (var line in commands) { var items = Regex.Split(line, @"\s+"); if (items.Length != 2) { if (pts.Count > 0) { if (pts.Count == 1) { gp.AddLine(pts.First(), pts.First()); } else { gp.AddLines(pts.ToArray()); } pts.Clear(); } continue; } float x, y; if (float.TryParse(items[0], out x) && float.TryParse(items[1], out y)) { pts.Add(new PointF(x, y)); } } Color bgcolor = Color.Black; if (opts.ContainsKey("bgcolor")) { bgcolor = Color.FromName(opts["bgcolor"]); } Color fgcolor = Color.White; if (opts.ContainsKey("fgcolor")) { fgcolor = Color.FromName(opts["fgcolor"]); } float pensize = 1.0f; if (opts.ContainsKey("pensize")) { float val; if (float.TryParse(opts["pensize"], out val)) { pensize = val; } } string title = "fwfw drawer"; if (opts.ContainsKey("title")) { title = opts["title"]; } int width = 512; if (opts.ContainsKey("width")) { int val; if (int.TryParse(opts["width"], out val)) { width = val; } } int height = 512; if (opts.ContainsKey("height")) { int val; if (int.TryParse(opts["height"], out val)) { height = val; } } Form f = new Form(); f.Text = title; f.StartPosition = FormStartPosition.CenterScreen; f.Size = new Size(width, height); f.Resize += (s, e) => { Bitmap bitmap = new Bitmap(f.ClientRectangle.Width, f.ClientRectangle.Height); Graphics g = Graphics.FromImage(bitmap); g.FillRectangle(new SolidBrush(bgcolor), f.ClientRectangle); g.DrawPath(new Pen(fgcolor, pensize), gp); g.Dispose(); f.BackgroundImage = bitmap; }; f.MouseClick += (s, e) => { // var loc = f.PointToClient(e.Location); Console.Out.WriteLine("{e.Location.X}\t{e.Location.Y}"); }; f.Shown += (s, e) => { Bitmap bitmap = new Bitmap(f.ClientRectangle.Width, f.ClientRectangle.Height); Graphics g = Graphics.FromImage(bitmap); g.FillRectangle(new SolidBrush(bgcolor), f.ClientRectangle); g.DrawPath(new Pen(fgcolor, pensize), gp); g.Dispose(); f.BackgroundImage = bitmap; }; f.ShowDialog(); return 0; }
/// <summary> /// Creates a path based on a polygon. /// </summary> private System.Drawing.Drawing2D.GraphicsPath CreatePath( C2DPolyBase Poly) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); if (Poly.Lines.Count == 0) return gp; for (int i = 0; i < Poly.Lines.Count; i++) { if (Poly.Lines[i] is C2DLine) { C2DPoint ptFrom = Poly.Lines[i].GetPointFrom(); C2DPoint ptTo = Poly.Lines[i].GetPointTo(); ScaleAndOffSet(ptFrom); ScaleAndOffSet(ptTo); gp.AddLine((int)ptFrom.x, (int)ptFrom.y, (int)ptTo.x, (int)ptTo.y); } else if (Poly.Lines[i] is C2DArc) { C2DRect Rect = new C2DRect(); int nStartAngle = 0; int nSweepAngle = 0; GetArcParameters(Poly.Lines[i] as C2DArc, Rect, ref nStartAngle, ref nSweepAngle); if (nSweepAngle == 0) nSweepAngle = 1; int Width = (int)Rect.Width(); if (Width == 0) Width = 1; int Height = (int)Rect.Height(); if (Height == 0) Height = 1; gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y, Width, Height, nStartAngle, nSweepAngle); } } gp.CloseFigure(); return gp; }
protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case 0xf: Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.FromArgb(45, 45, 48)); g.FillRectangle(BorderBrush, this.ClientRectangle); //Draw the background of the dropdown button Rectangle rect = new Rectangle(this.Width - 17, 0, 17, this.Height); g.FillRectangle(DropButtonBrush, rect); // Draw the name of the selected item if (this.DropDownStyle == ComboBoxStyle.DropDownList) { g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), 2, (this.Height / 2) - (this.Font.Size / 2)); } //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); if(this.DroppedDown) { ArrowBrush = new SolidBrush(Color.FromArgb(0, 122, 204)); } else { ArrowBrush = new SolidBrush(Color.FromArgb(153, 153, 153)); } g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //Draw the arrow g.FillPath(ArrowBrush, pth); break; default: break; } }
/// <summary> /// Draws a triangle filled. /// </summary> public void DrawFilled(C2DTriangle Triangle, Graphics graphics, Brush brush) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); C2DPoint pt1 = new C2DPoint(Triangle.p1); C2DPoint pt2 = new C2DPoint(Triangle.p2); C2DPoint pt3 = new C2DPoint(Triangle.p3); ScaleAndOffSet(pt1); ScaleAndOffSet(pt2); ScaleAndOffSet(pt3); gp.AddLine((int)pt1.x, (int)pt1.y, (int)pt2.x, (int)pt2.y); gp.AddLine((int)pt2.x, (int)pt2.y, (int)pt3.x, (int)pt3.y); gp.AddLine((int)pt3.x, (int)pt3.y, (int)pt1.x, (int)pt1.y); graphics.FillPath(brush, gp); }
/*******************************/ /// <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; }
private void PaintOffice2003(ItemPaintArgs pa) { Graphics g=pa.Graphics; // When on docked toolbar it has a special look... Rectangle r=m_Rect; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (this.Orientation == eOrientation.Vertical) { // When on docked toolbar it has a special look... r.Y += 2; r.Height -= 1; r.X -= 2; r.Width += 2; path.AddLine(r.X, r.Y, r.X + 2, r.Y + 2); path.AddLine(r.Right - 2, r.Y + 2, r.Right, r.Y); path.AddLine(r.Right, r.Bottom - 2, r.Right - 2, r.Bottom); path.AddLine(r.X + 2, r.Bottom, r.X, r.Bottom - 2); path.CloseAllFigures(); } else { // When on docked toolbar it has a special look... r.X += 2; r.Width -= 1; r.Y -= 2; r.Height += 3; path.AddLine(r.X, r.Y, r.X + 2, r.Y + 2); path.AddLine(r.X + 2, r.Bottom - 2, r.X, r.Bottom); path.AddLine(r.Right - 2, r.Bottom, r.Right, r.Bottom - 2); path.AddLine(r.Right, r.Y + 2, r.Right - 2, r.Y); path.CloseAllFigures(); } System.Drawing.Drawing2D.SmoothingMode smooth=g.SmoothingMode; g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if(this.Expanded) { System.Drawing.Drawing2D.LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.ItemPressedBackground,pa.Colors.ItemPressedBackground2,pa.Colors.ItemPressedBackgroundGradientAngle); g.FillPath(gradient,path); gradient.Dispose(); } else if(m_MouseOver) { System.Drawing.Drawing2D.LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.ItemHotBackground,pa.Colors.ItemHotBackground2,pa.Colors.ItemHotBackgroundGradientAngle); g.FillPath(gradient,path); gradient.Dispose(); } else { System.Drawing.Drawing2D.LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.CustomizeBackground,pa.Colors.CustomizeBackground2,pa.Colors.CustomizeBackgroundGradientAngle); g.FillPath(gradient,path); gradient.Dispose(); } g.SmoothingMode=smooth; if (this.Orientation == eOrientation.Vertical) { g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2, r.Bottom - 10 + 1, r.Left + (m_Rect.Width - 4) / 2 + 4, r.Bottom - 10 + 1); g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 - 1 + 1, r.Top + 6 + 1, r.Left + (m_Rect.Width - 4) / 2 - 1 + 1, r.Top + 8 + 1); g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 + 3 + 1, r.Top + 6 + 1, r.Left + (m_Rect.Width - 4) / 2 + 3 + 1, r.Top + 8 + 1); g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 - 1 + 1, r.Top + 7 + 1, r.Left + (m_Rect.Width - 4) / 2 + 1, r.Top + 7 + 1); g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 + 3 + 1, r.Top + 7 + 1, r.Left + (m_Rect.Width - 4) / 2 + 4 + 1, r.Top + 7 + 1); // Draw Arrow using (Pen pen = new Pen(pa.Colors.CustomizeText, 1)) { g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2, r.Bottom - 10, r.Left + (m_Rect.Width - 4) / 2 + 4, r.Bottom - 10); g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2 - 1, r.Top + 6, r.Left + (m_Rect.Width - 4) / 2 - 1, r.Top + 8); g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2 + 3, r.Top + 6, r.Left + (m_Rect.Width - 4) / 2 + 3, r.Top + 8); g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2 - 1, r.Top + 7, r.Left + (m_Rect.Width - 4) / 2, r.Top + 7); g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2 + 3, r.Top + 7, r.Left + (m_Rect.Width - 4) / 2 + 4, r.Top + 7); } } else { g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 + 1, r.Bottom - 11 + 1, r.Left + (m_Rect.Width - 4) / 2 + 4 + 1, r.Bottom - 11 + 1); g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 - 1 + 1, r.Top + 6 + 1, r.Left + (m_Rect.Width - 4) / 2 - 1 + 1, r.Top + 8 + 1); g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 + 3 + 1, r.Top + 6 + 1, r.Left + (m_Rect.Width - 4) / 2 + 3 + 1, r.Top + 8 + 1); g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 - 1 + 1, r.Top + 7 + 1, r.Left + (m_Rect.Width - 4) / 2 + 1, r.Top + 7 + 1); g.DrawLine(SystemPens.HighlightText, r.Left + (m_Rect.Width - 4) / 2 + 3 + 1, r.Top + 7 + 1, r.Left + (m_Rect.Width - 4) / 2 + 4 + 1, r.Top + 7 + 1); // Draw Arrow Shade Point[] p = new Point[3]; p[0].X = r.Left + (m_Rect.Width - 4) / 2 + 2 + 1; p[0].Y = r.Bottom - 5 + 1; p[1].X = p[0].X - 2; p[1].Y = p[0].Y - 3; p[2].X = p[1].X + 5; p[2].Y = p[1].Y; using (SolidBrush brush = new SolidBrush(SystemColors.HighlightText)) g.FillPolygon(brush, p); // Draw Arrow using (Pen pen = new Pen(pa.Colors.CustomizeText, 1)) { g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2, r.Bottom - 11, r.Left + (m_Rect.Width - 4) / 2 + 4, r.Bottom - 11); g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2 - 1, r.Top + 6, r.Left + (m_Rect.Width - 4) / 2 - 1, r.Top + 8); g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2 + 3, r.Top + 6, r.Left + (m_Rect.Width - 4) / 2 + 3, r.Top + 8); g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2 - 1, r.Top + 7, r.Left + (m_Rect.Width - 4) / 2, r.Top + 7); g.DrawLine(pen, r.Left + (m_Rect.Width - 4) / 2 + 3, r.Top + 7, r.Left + (m_Rect.Width - 4) / 2 + 4, r.Top + 7); } p = new Point[3]; p[0].X = r.Left + (m_Rect.Width - 4) / 2 + 2; p[0].Y = r.Bottom - 5; p[1].X = p[0].X - 2; p[1].Y = p[0].Y - 3; p[2].X = p[1].X + 5; p[2].Y = p[1].Y; using (SolidBrush brush = new SolidBrush(pa.Colors.CustomizeText)) g.FillPolygon(brush, p); } }
static System.Drawing.Drawing2D.GraphicsPath ResolveGraphicsPath(GraphicsPath path) { //convert from graphics path to internal presentation System.Drawing.Drawing2D.GraphicsPath innerPath = path.InnerPath as System.Drawing.Drawing2D.GraphicsPath; if (innerPath != null) { return innerPath; } //-------- innerPath = new System.Drawing.Drawing2D.GraphicsPath(); path.InnerPath = innerPath; List<float> points; List<PathCommand> cmds; GraphicsPath.GetPathData(path, out points, out cmds); int j = cmds.Count; int p_index = 0; for (int i = 0; i < j; ++i) { PathCommand cmd = cmds[i]; switch (cmd) { default: throw new NotSupportedException(); case PathCommand.Arc: innerPath.AddArc( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3], points[p_index + 4], points[p_index + 5]); p_index += 6; break; case PathCommand.Bezier: innerPath.AddBezier( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3], points[p_index + 4], points[p_index + 5], points[p_index + 6], points[p_index + 7]); p_index += 8; break; case PathCommand.CloseFigure: innerPath.CloseFigure(); break; case PathCommand.Ellipse: innerPath.AddEllipse( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3]); p_index += 4; break; case PathCommand.Line: innerPath.AddLine( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3]); p_index += 4; break; case PathCommand.Rect: innerPath.AddRectangle( new System.Drawing.RectangleF( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3])); p_index += 4; break; case PathCommand.StartFigure: break; } } return innerPath; }
private System.Drawing.Drawing2D.GraphicsPath RoundRectangle(Rectangle r, int radius, Corners corners) { //Make sure the Path fits inside the rectangle r.Width -= 1; r.Height -= 1; //Scale the radius if it's too large to fit. if (radius > (r.Width)) radius = r.Width; if (radius > (r.Height)) radius = r.Height; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (radius <= 0) path.AddRectangle(r); else if ((corners & Corners.TopLeft) == Corners.TopLeft) path.AddArc(r.Left, r.Top, radius, radius, 180, 90); else path.AddLine(r.Left, r.Top, r.Left, r.Top); if ((corners & Corners.TopRight) == Corners.TopRight) path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90); else path.AddLine(r.Right, r.Top, r.Right, r.Top); if ((corners & Corners.BottomRight) == Corners.BottomRight) path.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0, 90); else path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom); if ((corners & Corners.BottomLeft) == Corners.BottomLeft) path.AddArc(r.Left, r.Bottom - radius, radius, radius, 90, 90); else path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom); path.CloseFigure(); return path; }
/// <summary> /// Creates a GraphicsPath object and adds a line to it. /// </summary> /// <param name="p1">The starting point of the line.</param> /// <param name="p2">The endpoint of the line.</param> /// <returns>Returns a GraphicsPath object containing the line</returns> public static System.Drawing.Drawing2D.GraphicsPath CreateLine2DPath(System.Drawing.PointF p1, System.Drawing.PointF p2) { System.Drawing.Drawing2D.GraphicsPath linePath = new System.Drawing.Drawing2D.GraphicsPath(); linePath.AddLine(p1, p2); return linePath; }
public static void DrawRoundedRectangle(Graphics gfx, Rectangle Bounds, int CornerRadius, Pen DrawPen, Color FillColor) { System.Drawing.Drawing2D.GraphicsPath gfxPath = new System.Drawing.Drawing2D.GraphicsPath(); DrawPen.EndCap = DrawPen.StartCap = System.Drawing.Drawing2D.LineCap.Round; gfxPath.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); gfxPath.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); gfxPath.AddLine(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, Bounds.X, Bounds.Y + CornerRadius / 2); gfx.FillPath(new SolidBrush(FillColor), gfxPath); gfx.DrawPath(DrawPen, gfxPath); }
private System.Drawing.Drawing2D.GraphicsPath GetPath(int index) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.Reset(); Rectangle rect = this.GetTabRect(index); if (index == 0) { path.AddLine(rect.Left + 1, rect.Bottom + 1, rect.Left + rect.Height, rect.Top + 2); path.AddLine(rect.Left + rect.Height + 4, rect.Top, rect.Right - 3, rect.Top); path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1); } else { if (index == this.SelectedIndex) { path.AddLine(rect.Left + 5 - rect.Height, rect.Bottom + 1, rect.Left + 4, rect.Top + 2); path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top); path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1); path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left + 5 - rect.Height, rect.Bottom + 1); } else { path.AddLine(rect.Left, rect.Top + 6, rect.Left + 4, rect.Top + 2); path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top); path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1); path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left, rect.Bottom + 1); } } return path; }