void MainForm_Paint (object sender, PaintEventArgs e) { Graphics g = e.Graphics; GraphicsPath path = new GraphicsPath (); Rectangle borderect = new Rectangle (49, 49, 252, 252); g.FillRectangle (new SolidBrush (Color.White), borderect); int Diameter = 16; Rectangle baserect = new Rectangle (50, 50, 249, 249); Rectangle arcrect = new Rectangle (baserect.Location, new Size (Diameter, Diameter)); // handle top left corner path.AddArc (arcrect, 180, 90); // handle top right corner arcrect.X = baserect.Right - Diameter; path.AddArc (arcrect, 270, 90); // handle baserect right corner arcrect.Y = baserect.Bottom - Diameter; path.AddArc (arcrect, 0, 90); // handle bottom left corner arcrect.X = baserect.Left; path.AddArc (arcrect, 90, 90); path.CloseFigure (); g.DrawPath (Pens.SteelBlue, path); }
static internal GraphicsPath CreateRound(Rectangle r, int slope) { CreateRoundPath = new GraphicsPath(FillMode.Winding); CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f); CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f); CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f); CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f); CreateRoundPath.CloseFigure(); return CreateRoundPath; }
public static GraphicsPath CreateRoundRect(float x, float y, float width, float height, float radius) { GraphicsPath gp = new GraphicsPath(); gp.AddLine(x + radius, y, x + width - (radius * 2), y); gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); gp.AddLine(x, y + height - (radius * 2), x, y + radius); gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); gp.CloseFigure(); return gp; }
public static GraphicsPath CreateRoundedRectangle(SizeF size, PointF location) { int cornerSize = (int)GraphConstants.CornerSize * 2; var height = size.Height; var width = size.Width; var left = location.X; var top = location.Y; var right = location.X + width; var bottom = location.Y + height; var path = new GraphicsPath(FillMode.Winding); path.AddArc(left, top, cornerSize, cornerSize, 180, 90); path.AddArc(right - cornerSize, top, cornerSize, cornerSize, 270, 90); path.AddArc(right - cornerSize, bottom - cornerSize, cornerSize, cornerSize, 0, 90); path.AddArc(left, bottom - cornerSize, cornerSize, cornerSize, 90, 90); path.CloseFigure(); return path; }
protected override GraphicsPath Draw3DSurface(DataPoint3D firstPoint, DataPoint3D secondPoint, bool reversed, ChartArea area, ChartGraphics graph, Matrix3D matrix, LightStyle lightStyle, DataPoint3D prevDataPointEx, float positionZ, float depth, ArrayList points, int pointIndex, int pointLoopIndex, float tension, DrawingOperationTypes operationType, LineSegmentType surfaceSegmentType, float topDarkening, float bottomDarkening, PointF thirdPointPosition, PointF fourthPointPosition, bool clippedSegment, bool clipOnTop, bool clipOnBottom) { GraphicsPath graphicsPath = ((operationType & DrawingOperationTypes.CalcElementPath) == DrawingOperationTypes.CalcElementPath) ? new GraphicsPath() : null; if (Math.Round(firstPoint.xPosition, 3) == Math.Round(secondPoint.xPosition, 3) && Math.Round(firstPoint.yPosition, 3) == Math.Round(secondPoint.yPosition, 3)) { return(graphicsPath); } DataPoint3D dataPoint3D = secondPoint; if (prevDataPointEx.dataPoint.Empty) { dataPoint3D = prevDataPointEx; } else if (firstPoint.index > secondPoint.index) { dataPoint3D = firstPoint; } Color color = useBorderColor ? dataPoint3D.dataPoint.BorderColor : dataPoint3D.dataPoint.Color; ChartDashStyle borderStyle = dataPoint3D.dataPoint.BorderStyle; if (dataPoint3D.dataPoint.Empty && dataPoint3D.dataPoint.Color == Color.Empty) { color = Color.Gray; } if (dataPoint3D.dataPoint.Empty && dataPoint3D.dataPoint.BorderStyle == ChartDashStyle.NotSet) { borderStyle = ChartDashStyle.Solid; } float num = (float)Math.Round(vAxis.GetPosition(vAxis.Crossing), 3); float num2 = (float)Math.Min(firstPoint.xPosition, secondPoint.xPosition); float val = (float)Math.Min(firstPoint.yPosition, secondPoint.yPosition); val = Math.Min(val, num); float num3 = (float)Math.Max(firstPoint.xPosition, secondPoint.xPosition); float val2 = (float)Math.Max(firstPoint.yPosition, secondPoint.yPosition); val2 = Math.Max(val2, num); RectangleF position = new RectangleF(num2, val, num3 - num2, val2 - val); SurfaceNames visibleSurfaces = graph.GetVisibleSurfaces(position, positionZ, depth, matrix); bool upSideDown = false; if ((decimal)firstPoint.yPosition >= (decimal)num && (decimal)secondPoint.yPosition >= (decimal)num) { upSideDown = true; bool num4 = (visibleSurfaces & SurfaceNames.Top) == SurfaceNames.Top; bool flag = (visibleSurfaces & SurfaceNames.Bottom) == SurfaceNames.Bottom; visibleSurfaces ^= SurfaceNames.Bottom; visibleSurfaces ^= SurfaceNames.Top; if (num4) { visibleSurfaces |= SurfaceNames.Bottom; } if (flag) { visibleSurfaces |= SurfaceNames.Top; } } GetTopSurfaceVisibility(area, firstPoint, secondPoint, upSideDown, positionZ, depth, matrix, ref visibleSurfaces); GetBottomPointsPosition(common, area, num, ref firstPoint, ref secondPoint, thirdPointPosition, fourthPointPosition, out PointF thirdPoint, out PointF fourthPoint); if (!float.IsNaN(thirdPointPosition.Y)) { thirdPoint.Y = thirdPointPosition.Y; } if (!float.IsNaN(fourthPointPosition.Y)) { fourthPoint.Y = fourthPointPosition.Y; } if (float.IsNaN(thirdPoint.X) || float.IsNaN(thirdPoint.Y) || float.IsNaN(fourthPoint.X) || float.IsNaN(fourthPoint.Y)) { return(graphicsPath); } if (clipOnTop && ClipTopPoints(graphicsPath, ref firstPoint, ref secondPoint, reversed, area, graph, matrix, lightStyle, prevDataPointEx, positionZ, depth, points, pointIndex, pointLoopIndex, tension, operationType, surfaceSegmentType, topDarkening, bottomDarkening)) { return(graphicsPath); } if (clipOnBottom && ClipBottomPoints(graphicsPath, ref firstPoint, ref secondPoint, ref thirdPoint, ref fourthPoint, reversed, area, graph, matrix, lightStyle, prevDataPointEx, positionZ, depth, points, pointIndex, pointLoopIndex, tension, operationType, surfaceSegmentType, topDarkening, bottomDarkening)) { return(graphicsPath); } if ((Math.Round((decimal)firstPoint.yPosition, 3) > (decimal)num + 0.001m && Math.Round((decimal)secondPoint.yPosition, 3) < (decimal)num - 0.001m) || (Math.Round((decimal)firstPoint.yPosition, 3) < (decimal)num - 0.001m && Math.Round((decimal)secondPoint.yPosition, 3) > (decimal)num + 0.001m)) { DataPoint3D axisIntersection = GetAxisIntersection(firstPoint, secondPoint, num); for (int i = 0; i <= 1; i++) { GraphicsPath graphicsPath2 = null; if ((i == 0 && !reversed) || (i == 1 && reversed)) { axisIntersection.dataPoint = secondPoint.dataPoint; axisIntersection.index = secondPoint.index; graphicsPath2 = Draw3DSurface(firstPoint, axisIntersection, reversed, area, graph, matrix, lightStyle, prevDataPointEx, positionZ, depth, points, pointIndex, pointLoopIndex, tension, operationType, surfaceSegmentType, topDarkening, bottomDarkening, new PointF(float.NaN, float.NaN), new PointF(float.NaN, float.NaN), clippedSegment, clipOnTop, clipOnBottom); } if ((i == 1 && !reversed) || (i == 0 && reversed)) { axisIntersection.dataPoint = firstPoint.dataPoint; axisIntersection.index = firstPoint.index; graphicsPath2 = Draw3DSurface(axisIntersection, secondPoint, reversed, area, graph, matrix, lightStyle, prevDataPointEx, positionZ, depth, points, pointIndex, pointLoopIndex, tension, operationType, surfaceSegmentType, topDarkening, bottomDarkening, new PointF(float.NaN, float.NaN), new PointF(float.NaN, float.NaN), clippedSegment, clipOnTop, clipOnBottom); } if (graphicsPath != null && graphicsPath2 != null && graphicsPath2.PointCount > 0) { graphicsPath.AddPath(graphicsPath2, connect: true); } } return(graphicsPath); } if (Math.Round(firstPoint.xPosition, 3) == Math.Round(secondPoint.xPosition, 3) && Math.Round(firstPoint.yPosition, 3) == Math.Round(secondPoint.yPosition, 3)) { return(graphicsPath); } for (int j = 1; j <= 2; j++) { SurfaceNames[] obj = new SurfaceNames[6] { SurfaceNames.Back, SurfaceNames.Bottom, SurfaceNames.Top, SurfaceNames.Left, SurfaceNames.Right, SurfaceNames.Front }; LineSegmentType lineSegmentType = LineSegmentType.Middle; SurfaceNames[] array = obj; foreach (SurfaceNames surfaceNames in array) { if (ChartGraphics3D.ShouldDrawLineChartSurface(area, area.reverseSeriesOrder, surfaceNames, visibleSurfaces, color, points, firstPoint, secondPoint, multiSeries, reversed, ref lineSegmentType) != j || (allPointsLoopsNumber == 2 && (operationType & DrawingOperationTypes.DrawElement) == DrawingOperationTypes.DrawElement && ((pointLoopIndex == 0 && (surfaceNames == SurfaceNames.Front || (j == 2 && (surfaceNames == SurfaceNames.Left || surfaceNames == SurfaceNames.Right)))) || (pointLoopIndex == 1 && (surfaceNames == SurfaceNames.Back || surfaceNames != SurfaceNames.Front) && (j == 1 || (surfaceNames != SurfaceNames.Left && surfaceNames != SurfaceNames.Right)))))) { continue; } Color color2 = color; Color color3 = dataPoint3D.dataPoint.BorderColor; if (j == 1) { if (color2.A == byte.MaxValue) { continue; } color2 = Color.Transparent; if (color3 == Color.Empty) { color3 = ChartGraphics.GetGradientColor(color, Color.Black, 0.2); } } bool flag2 = showPointLines; if (surfaceSegmentType == LineSegmentType.Middle) { flag2 = false; } if (clippedSegment && surfaceNames != SurfaceNames.Top && surfaceNames != SurfaceNames.Bottom) { continue; } GraphicsPath graphicsPath3 = null; switch (surfaceNames) { case SurfaceNames.Top: { Color backColor = (topDarkening == 0f) ? color2 : ChartGraphics.GetGradientColor(color2, Color.Black, topDarkening); Color borderColor = (topDarkening == 0f) ? color3 : ChartGraphics.GetGradientColor(color3, Color.Black, topDarkening); graphicsPath3 = graph.Draw3DSurface(area, matrix, lightStyle, surfaceNames, positionZ, depth, backColor, borderColor, dataPoint3D.dataPoint.BorderWidth, borderStyle, firstPoint, secondPoint, points, pointIndex, 0f, operationType, surfaceSegmentType, flag2, forceThickBorder: false, area.reverseSeriesOrder, multiSeries, 0, clipInsideArea: true); break; } case SurfaceNames.Bottom: { DataPoint3D dataPoint3D12 = new DataPoint3D(); dataPoint3D12.index = firstPoint.index; dataPoint3D12.dataPoint = firstPoint.dataPoint; dataPoint3D12.xPosition = firstPoint.xPosition; dataPoint3D12.yPosition = thirdPoint.Y; DataPoint3D dataPoint3D13 = new DataPoint3D(); dataPoint3D13.index = secondPoint.index; dataPoint3D13.dataPoint = secondPoint.dataPoint; dataPoint3D13.xPosition = secondPoint.xPosition; dataPoint3D13.yPosition = fourthPoint.Y; Color backColor2 = (bottomDarkening == 0f) ? color2 : ChartGraphics.GetGradientColor(color2, Color.Black, topDarkening); Color borderColor2 = (bottomDarkening == 0f) ? color3 : ChartGraphics.GetGradientColor(color3, Color.Black, topDarkening); graphicsPath3 = graph.Draw3DSurface(area, matrix, lightStyle, surfaceNames, positionZ, depth, backColor2, borderColor2, dataPoint3D.dataPoint.BorderWidth, borderStyle, dataPoint3D12, dataPoint3D13, points, pointIndex, 0f, operationType, surfaceSegmentType, flag2, forceThickBorder: false, area.reverseSeriesOrder, multiSeries, 0, clipInsideArea: true); break; } case SurfaceNames.Left: if (surfaceSegmentType == LineSegmentType.Single || (!area.reverseSeriesOrder && surfaceSegmentType == LineSegmentType.First) || (area.reverseSeriesOrder && surfaceSegmentType == LineSegmentType.Last)) { DataPoint3D dataPoint3D4 = (firstPoint.xPosition <= secondPoint.xPosition) ? firstPoint : secondPoint; DataPoint3D dataPoint3D5 = new DataPoint3D(); dataPoint3D5.index = dataPoint3D4.index; dataPoint3D5.dataPoint = dataPoint3D4.dataPoint; dataPoint3D5.xPosition = dataPoint3D4.xPosition; dataPoint3D5.yPosition = ((firstPoint.xPosition <= secondPoint.xPosition) ? thirdPoint.Y : fourthPoint.Y); DataPoint3D dataPoint3D6 = new DataPoint3D(); dataPoint3D6.index = dataPoint3D4.index; dataPoint3D6.dataPoint = dataPoint3D4.dataPoint; dataPoint3D6.xPosition = dataPoint3D4.xPosition; dataPoint3D6.yPosition = dataPoint3D4.yPosition; graphicsPath3 = graph.Draw3DSurface(area, matrix, lightStyle, surfaceNames, positionZ, depth, color2, color3, dataPoint3D.dataPoint.BorderWidth, borderStyle, dataPoint3D5, dataPoint3D6, points, pointIndex, 0f, operationType, LineSegmentType.Single, forceThinBorder: true, forceThickBorder: true, area.reverseSeriesOrder, multiSeries, 0, clipInsideArea: true); } break; case SurfaceNames.Right: if (surfaceSegmentType == LineSegmentType.Single || (!area.reverseSeriesOrder && surfaceSegmentType == LineSegmentType.Last) || (area.reverseSeriesOrder && surfaceSegmentType == LineSegmentType.First)) { DataPoint3D dataPoint3D9 = (secondPoint.xPosition >= firstPoint.xPosition) ? secondPoint : firstPoint; DataPoint3D dataPoint3D10 = new DataPoint3D(); dataPoint3D10.index = dataPoint3D9.index; dataPoint3D10.dataPoint = dataPoint3D9.dataPoint; dataPoint3D10.xPosition = dataPoint3D9.xPosition; dataPoint3D10.yPosition = ((secondPoint.xPosition >= firstPoint.xPosition) ? fourthPoint.Y : thirdPoint.Y); DataPoint3D dataPoint3D11 = new DataPoint3D(); dataPoint3D11.index = dataPoint3D9.index; dataPoint3D11.dataPoint = dataPoint3D9.dataPoint; dataPoint3D11.xPosition = dataPoint3D9.xPosition; dataPoint3D11.yPosition = dataPoint3D9.yPosition; graphicsPath3 = graph.Draw3DSurface(area, matrix, lightStyle, surfaceNames, positionZ, depth, color2, color3, dataPoint3D.dataPoint.BorderWidth, borderStyle, dataPoint3D10, dataPoint3D11, points, pointIndex, 0f, operationType, LineSegmentType.Single, forceThinBorder: true, forceThickBorder: true, area.reverseSeriesOrder, multiSeries, 0, clipInsideArea: true); } break; case SurfaceNames.Back: { DataPoint3D dataPoint3D7 = new DataPoint3D(); dataPoint3D7.index = firstPoint.index; dataPoint3D7.dataPoint = firstPoint.dataPoint; dataPoint3D7.xPosition = firstPoint.xPosition; dataPoint3D7.yPosition = thirdPoint.Y; DataPoint3D dataPoint3D8 = new DataPoint3D(); dataPoint3D8.index = secondPoint.index; dataPoint3D8.dataPoint = secondPoint.dataPoint; dataPoint3D8.xPosition = secondPoint.xPosition; dataPoint3D8.yPosition = fourthPoint.Y; SurfaceNames thinBorders2 = (SurfaceNames)0; if (flag2) { switch (surfaceSegmentType) { case LineSegmentType.Single: thinBorders2 = (SurfaceNames.Left | SurfaceNames.Right); break; case LineSegmentType.First: thinBorders2 = SurfaceNames.Left; break; case LineSegmentType.Last: thinBorders2 = SurfaceNames.Right; break; } } graphicsPath3 = graph.Draw3DPolygon(area, matrix, lightStyle, surfaceNames, positionZ, color2, color3, dataPoint3D.dataPoint.BorderWidth, borderStyle, firstPoint, secondPoint, dataPoint3D8, dataPoint3D7, points, pointIndex, 0f, operationType, lineSegmentType, thinBorders2); break; } case SurfaceNames.Front: { DataPoint3D dataPoint3D2 = new DataPoint3D(); dataPoint3D2.index = firstPoint.index; dataPoint3D2.dataPoint = firstPoint.dataPoint; dataPoint3D2.xPosition = firstPoint.xPosition; dataPoint3D2.yPosition = thirdPoint.Y; DataPoint3D dataPoint3D3 = new DataPoint3D(); dataPoint3D3.index = secondPoint.index; dataPoint3D3.dataPoint = secondPoint.dataPoint; dataPoint3D3.xPosition = secondPoint.xPosition; dataPoint3D3.yPosition = fourthPoint.Y; if (area.reverseSeriesOrder) { switch (lineSegmentType) { case LineSegmentType.First: lineSegmentType = LineSegmentType.Last; break; case LineSegmentType.Last: lineSegmentType = LineSegmentType.First; break; } } if (surfaceSegmentType != 0 && (surfaceSegmentType == LineSegmentType.Middle || (surfaceSegmentType == LineSegmentType.First && lineSegmentType != LineSegmentType.First) || (surfaceSegmentType == LineSegmentType.Last && lineSegmentType != LineSegmentType.Last))) { lineSegmentType = LineSegmentType.Middle; } SurfaceNames thinBorders = (SurfaceNames)0; if (flag2) { switch (surfaceSegmentType) { case LineSegmentType.Single: thinBorders = (SurfaceNames.Left | SurfaceNames.Right); break; case LineSegmentType.First: thinBorders = SurfaceNames.Left; break; case LineSegmentType.Last: thinBorders = SurfaceNames.Right; break; } } graphicsPath3 = graph.Draw3DPolygon(area, matrix, lightStyle, surfaceNames, positionZ + depth, color2, color3, dataPoint3D.dataPoint.BorderWidth, borderStyle, firstPoint, secondPoint, dataPoint3D3, dataPoint3D2, points, pointIndex, 0f, operationType, lineSegmentType, thinBorders); break; } } if (j == 2 && graphicsPath != null && graphicsPath3 != null && graphicsPath3.PointCount > 0) { graphicsPath.CloseFigure(); graphicsPath.SetMarkers(); graphicsPath.AddPath(graphicsPath3, connect: true); } } } return(graphicsPath); }
private void RenderItemBackgroundPressed(ToolStripItemRenderEventArgs e) { if (Theme.Standard.Style == RibbonOrbStyle.Office_2013) { Rectangle rectBorder = new Rectangle(1, 1, e.Item.Width - 1, e.Item.Height - 1); Rectangle rect = new Rectangle(2, 2, e.Item.Width - 2, e.Item.Height - 2); using (SolidBrush b = new SolidBrush(Theme.Standard.RendererColorTable.ButtonPressed_2013)) { using (SolidBrush sb = new SolidBrush(Theme.Standard.RendererColorTable.ButtonBorderOut)) { e.Graphics.FillRectangle(sb, rectBorder); } e.Graphics.FillRectangle(b, rect); } } else { Rectangle rectBorder = new Rectangle(1, 1, e.Item.Width - 1, e.Item.Height - 1); Rectangle rect = new Rectangle(2, 2, e.Item.Width - 2, e.Item.Height - 2); Rectangle innerR = Rectangle.FromLTRB(1, 1, e.Item.Width - 2, e.Item.Height - 2); Rectangle glossyR = Rectangle.FromLTRB(1, 1, e.Item.Width - 2, 1 + Convert.ToInt32(e.Item.Bounds.Height * .36)); using (SolidBrush brus = new SolidBrush(Theme.Standard.RendererColorTable.ButtonPressedBgOut)) { e.Graphics.FillRectangle(brus, rectBorder); } //Border using (Pen p = new Pen(Theme.Standard.RendererColorTable.ButtonPressedBorderOut)) { e.Graphics.DrawRectangle(p, rectBorder); } //Inner border Rectangle RoundedRect = Rectangle.Round(innerR); using (Pen p = new Pen(Theme.Standard.RendererColorTable.ButtonPressedBorderIn)) { e.Graphics.DrawRectangle(p, RoundedRect); } #region Main Bg using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(new Rectangle(1, 1, e.Item.Width, e.Item.Height * 2)); path.CloseFigure(); using (PathGradientBrush gradient = new PathGradientBrush(path)) { gradient.WrapMode = WrapMode.Clamp; gradient.CenterPoint = new PointF(Convert.ToSingle(1 + e.Item.Width / 2), Convert.ToSingle(e.Item.Bounds.Height)); gradient.CenterColor = Theme.Standard.RendererColorTable.ButtonPressedBgCenter; gradient.SurroundColors = new[] { Theme.Standard.RendererColorTable.ButtonPressedBgOut }; Blend blend = new Blend(3) { Factors = new[] { 0f, 0.8f, 0f }, Positions = new[] { 0f, 0.30f, 1f } }; Region lastClip = e.Graphics.Clip; Region newClip = new Region(rectBorder); newClip.Intersect(lastClip); e.Graphics.SetClip(newClip.GetBounds(e.Graphics)); e.Graphics.FillPath(gradient, path); e.Graphics.Clip = lastClip; } } #endregion //Glossy effect using (GraphicsPath path = new GraphicsPath()) { path.AddRectangle(Rectangle.Round(glossyR)); using (LinearGradientBrush b = new LinearGradientBrush(glossyR, Theme.Standard.RendererColorTable.ButtonPressedGlossyNorth, Theme.Standard.RendererColorTable.ButtonPressedGlossySouth, 90)) { b.WrapMode = WrapMode.TileFlipXY; e.Graphics.FillPath(b, path); } } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics graphics = e.Graphics; graphics.SmoothingMode = SmoothingMode.HighQuality; Pen pen = new Pen(new SolidBrush(Color.FromArgb(180, Color.Gray)), 1.5f); GraphicsPath mainSketch = new GraphicsPath(); Color ParentColor; float[] dashValues = { 4, 2 }; pen.DashPattern = dashValues; if (Parent is IMaterialControl) { ParentColor = ((MaterialCard)Parent).CardColor; } else { ParentColor = Parent.BackColor; } graphics.Clear(ParentColor); if (Enabled) { switch (comboBoxType) { case BoxType.Normal: graphics.DrawLine(new Pen(new SolidBrush((MouseState == MouseState.OUT) ? Color.Gray : primaryColor), (MouseState == MouseState.OUT) ? 1.3f : 1.6f), 0, Height - 4, Width, Height - 4); break; case BoxType.Outlined: mainSketch = GraphicHelper.GetRoundedRectangle(2, topPadding / 2, Width - 4, Height - topPadding / 2 - 2, 4); if (Focused) { graphics.DrawPath(new Pen(primaryColor, 2.2f), mainSketch); } else { graphics.DrawPath(new Pen((MouseState == MouseState.OUT) ? Color.DimGray : primaryColor, (MouseState == MouseState.OUT) ? 1.3f : 1.6f), mainSketch); } break; case BoxType.Filled: mainSketch = GraphicHelper.GetRoundedRectangle(0, 0, Width, Height - 2, 4); graphics.FillPath(new SolidBrush(Color.FromArgb(Focused ? 255 : 200, Color.WhiteSmoke)), mainSketch); graphics.DrawLine(new Pen(new SolidBrush((MouseState == MouseState.OUT) ? Color.Gray : primaryColor), (MouseState == MouseState.OUT) ? 1.3f : 1.6f), 0, Height - 4, Width, Height - 4); break; default: break; } } else { switch (comboBoxType) { case BoxType.Normal: graphics.DrawLine(pen, 0, Height - 4, Width, Height - 4); break; case BoxType.Outlined: mainSketch = GraphicHelper.GetRoundedRectangle(2, topPadding / 2, Width - 4, Height - topPadding / 2 - 2, 4); graphics.DrawPath(pen, mainSketch); break; case BoxType.Filled: mainSketch = GraphicHelper.GetRoundedRectangle(0, 0, Width, Height - 2, 4); graphics.FillPath(new SolidBrush(Color.WhiteSmoke), mainSketch); graphics.DrawLine(pen, 0, Height - 4, Width, Height - 4); break; default: break; } } if (comboBoxType == BoxType.Outlined) { SizeF hintRec = this.CreateGraphics().MeasureString(hintText, hintFont); graphics.FillRectangle(new SolidBrush(ParentColor), 7, hintLocation / 2, hintRec.Width, hintRec.Height); } graphics.DrawString(hintText, hintFont, new SolidBrush(Focused ? primaryColor : (SelectedItem != null) ? Color.Gray : Color.Silver), 8, hintLocation, textAglignment); if (SelectedItem != null) { graphics.DrawString(SelectedItem.ToString(), this.Font, new SolidBrush(ForeColor), 8, Height / 2 + topPadding / 2 - 2, textAglignment); } GraphicsPath triangle = new GraphicsPath(); triangle.AddLine(trianglePoints[0], trianglePoints[1]); triangle.AddLine(trianglePoints[1], trianglePoints[2]); triangle.AddLine(trianglePoints[0], trianglePoints[2]); triangle.CloseFigure(); graphics.FillPath(new SolidBrush((Focused || MouseState == MouseState.HOVER) ? primaryColor : Color.Gray), triangle); if (comboBoxType != BoxType.Outlined) { graphics.DrawLine(new Pen(new SolidBrush(primaryColor), 2.6f), firstDot, Height - 4, middleDot, Height - 4); graphics.DrawLine(new Pen(new SolidBrush(primaryColor), 2.6f), middleDot, Height - 4, lastDot, Height - 4); } mainSketch.Dispose(); pen.Dispose(); }
/// <summary> /// 建立带有圆角样式的路径。 /// </summary> /// <param name="rect">用来建立路径的矩形。</param> /// <param name="_radius">圆角的大小。</param> /// <param name="style">圆角的样式。</param> /// <param name="correction">是否把矩形长宽减 1,以便画出边框。</param> /// <returns>建立的路径。</returns> public static GraphicsPath CreatePath( Rectangle rect, int radius, RoundStyle style, bool correction) { GraphicsPath path = new GraphicsPath(); int radiusCorrection = correction ? 1 : 0; switch (style) { case RoundStyle.None: path.AddRectangle(rect); break; case RoundStyle.All: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); break; case RoundStyle.Left: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddLine( rect.Right - radiusCorrection, rect.Y, rect.Right - radiusCorrection, rect.Bottom - radiusCorrection); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); break; case RoundStyle.Right: path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddLine(rect.X, rect.Bottom - radiusCorrection, rect.X, rect.Y); break; case RoundStyle.Top: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddLine( rect.Right - radiusCorrection, rect.Bottom - radiusCorrection, rect.X, rect.Bottom - radiusCorrection); break; case RoundStyle.Bottom: path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); path.AddLine(rect.X, rect.Y, rect.Right - radiusCorrection, rect.Y); break; } path.CloseFigure(); return(path); }
/// <summary> /// Draws a tooltip. /// </summary> private void DrawToolTip(Graphics g, int x, string s) { bool onLeft = (x < ImageListView.ClientRectangle.Width / 2); int width = 200; Size sz = Size.Round(g.MeasureString(s, ImageListView.Font, width)); sz.Width += 20; sz.Height += 10; int y = 12; int arrowOffset = 15; if (!onLeft) { arrowOffset = sz.Width - 30; } if (!onLeft) { x -= sz.Width - 45; } int fillet = 10; if (fillet > sz.Height / 2) { fillet = sz.Height / 2; } int shadow = 3; using (GraphicsPath path = new GraphicsPath()) { path.AddLine(x - 20 + arrowOffset, y, x - 15 + arrowOffset, y - 10); path.AddLine(x - 15 + arrowOffset, y - 10, x - 10 + arrowOffset, y); path.AddLine(x - 10 + arrowOffset, y, x + sz.Width - 20 - fillet, y); path.AddArc(x + sz.Width - 20 - 2 * fillet, y, 2 * fillet, 2 * fillet, 270.0f, 90.0f); path.AddLine(x + sz.Width - 20, y + fillet, x + sz.Width - 20, y + sz.Height - fillet); path.AddArc(x + sz.Width - 20 - 2 * fillet, y + sz.Height - 2 * fillet, 2 * fillet, 2 * fillet, 0.0f, 90.0f); path.AddLine(x + sz.Width - 20 - fillet, y + sz.Height, x - 20 + fillet, y + sz.Height); path.AddArc(x - 20, y + sz.Height - 2 * fillet, 2 * fillet, 2 * fillet, 90.0f, 90.0f); path.AddLine(x - 20, y + sz.Height - fillet, x - 20, y + fillet); path.AddArc(x - 20, y, 2 * fillet, 2 * fillet, 180.0f, 90.0f); path.AddLine(x - 20 + fillet, y, x - 20 + arrowOffset, y); path.CloseFigure(); path.Transform(new Matrix(1, 0, 0, 1, shadow, shadow)); using (Brush b = new SolidBrush(Color.FromArgb(128, Color.Gray))) { g.FillPath(b, path); } path.Transform(new Matrix(1, 0, 0, 1, -shadow, -shadow)); using (Brush b = new LinearGradientBrush(path.GetBounds(), Color.BlanchedAlmond, Color.White, LinearGradientMode.ForwardDiagonal)) { g.FillPath(b, path); } using (Pen p = new Pen(SystemColors.InfoText)) { g.DrawPath(p, path); } using (Brush b = new SolidBrush(SystemColors.InfoText)) { g.DrawString(infoTexts[current], ImageListView.Font, b, new Rectangle(x - 20 + 10, y + 5, sz.Width - 16, sz.Height - 10)); } } }
protected GraphicsPath GetPath() { GraphicsPath graphPath = new GraphicsPath(); if (_BorderStyle == BorderStyle.Fixed3D) { graphPath.AddRectangle(ClientRectangle); } else { try { int curve = 0; Rectangle rect = ClientRectangle; int offset = 0; switch (_BorderStyle) { case BorderStyle.FixedSingle: offset = (int) Math.Ceiling(BorderWidth / 2.0d); curve = adjustedCurve; break; case BorderStyle.Fixed3D: break; case BorderStyle.None: curve = adjustedCurve; break; } if (curve == 0) { graphPath.AddRectangle(Rectangle.Inflate(rect, -offset, -offset)); } else { int rectWidth = rect.Width - 1 - offset; int rectHeight = rect.Height - 1 - offset; int curveWidth; if ((_CurveMode & CornerCurveMode.TopRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90); if ((_CurveMode & CornerCurveMode.BottomRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90); if ((_CurveMode & CornerCurveMode.BottomLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90); if ((_CurveMode & CornerCurveMode.TopLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90); graphPath.CloseFigure(); } } catch (Exception) { graphPath.AddRectangle(ClientRectangle); } } return graphPath; }
internal GraphicsPath CreateRoundRect(Rectangle r, int curve) { // Draw a border radius try { CreateRoundPath = new GraphicsPath(FillMode.Winding); CreateRoundPath.AddArc(r.X, r.Y, curve, curve, 180f, 90f); CreateRoundPath.AddArc(r.Right - curve, r.Y, curve, curve, 270f, 90f); CreateRoundPath.AddArc(r.Right - curve, r.Bottom - curve, curve, curve, 0f, 90f); CreateRoundPath.AddArc(r.X, r.Bottom - curve, curve, curve, 90f, 90f); CreateRoundPath.CloseFigure(); } catch (Exception ex) { MessageBox.Show(ex.Message + Environment.NewLine + Environment.NewLine + "Value must be either '1' or higher", "Invalid Integer", MessageBoxButtons.OK, MessageBoxIcon.Warning); // Return to the default border curve if the parameter is less than "1" _BorderCurve = 8; BorderCurve = 8; } return CreateRoundPath; }
public static GraphicsPath CreatePath(SvgPathElement element) { GraphicsPath gp = new GraphicsPath(); SvgPointF initPoint = new SvgPointF(0, 0); SvgPointF lastPoint = new SvgPointF(0, 0); SvgPointF ptXY = new SvgPointF(0, 0); SvgPathSeg segment = null; SvgPathSegMoveto pathMoveTo = null; SvgPathSegLineto pathLineTo = null; SvgPathSegCurveto pathCurveTo = null; SvgPathSegArc pathArc = null; SvgPathSegList segments = element.PathSegList; int nElems = segments.NumberOfItems; for (int i = 0; i < nElems; i++) { segment = segments.GetItem(i); switch (segment.PathType) { case SvgPathType.MoveTo: //if (DynamicCast.Cast(segment, out pathMoveTo)) pathMoveTo = (SvgPathSegMoveto)segment; gp.StartFigure(); lastPoint = initPoint = pathMoveTo.AbsXY; break; case SvgPathType.LineTo: //else if (DynamicCast.Cast(segment, out pathLineTo)) pathLineTo = (SvgPathSegLineto)segment; ptXY = pathLineTo.AbsXY; gp.AddLine(lastPoint.X, lastPoint.Y, ptXY.X, ptXY.Y); lastPoint = ptXY; break; case SvgPathType.CurveTo: //else if (DynamicCast.Cast(segment, out pathCurveTo)) pathCurveTo = (SvgPathSegCurveto)segment; SvgPointF xy = pathCurveTo.AbsXY; SvgPointF x1y1 = pathCurveTo.CubicX1Y1; SvgPointF x2y2 = pathCurveTo.CubicX2Y2; gp.AddBezier(lastPoint.X, lastPoint.Y, x1y1.X, x1y1.Y, x2y2.X, x2y2.Y, xy.X, xy.Y); lastPoint = xy; break; case SvgPathType.ArcTo: //else if (DynamicCast.Cast(segment, out pathArc)) pathArc = (SvgPathSegArc)segment; ptXY = pathArc.AbsXY; if (lastPoint.Equals(ptXY)) { // If the endpoints (x, y) and (x0, y0) are identical, then this // is equivalent to omitting the elliptical arc segment entirely. } else if (pathArc.R1.Equals(0) || pathArc.R2.Equals(0)) { // Ensure radii are valid gp.AddLine(lastPoint.X, lastPoint.Y, ptXY.X, ptXY.Y); } else { CalculatedArcValues calcValues = pathArc.GetCalculatedArcValues(); GraphicsPath subPath = new GraphicsPath(); subPath.StartFigure(); subPath.AddArc((float)(calcValues.Cx - calcValues.CorrRx), (float)(calcValues.Cy - calcValues.CorrRy), (float)calcValues.CorrRx * 2, (float)calcValues.CorrRy * 2, (float)calcValues.AngleStart, (float)calcValues.AngleExtent); Matrix matrix = new Matrix(); matrix.Translate(-(float)calcValues.Cx, -(float)calcValues.Cy); subPath.Transform(matrix); matrix = new Matrix(); matrix.Rotate((float)pathArc.Angle); subPath.Transform(matrix); matrix = new Matrix(); matrix.Translate((float)calcValues.Cx, (float)calcValues.Cy); subPath.Transform(matrix); gp.AddPath(subPath, true); } lastPoint = ptXY; break; case SvgPathType.Close: //else if (segment is SvgPathSegClosePath) gp.CloseFigure(); lastPoint = initPoint; break; } } string fillRule = element.GetPropertyValue("fill-rule"); if (fillRule == "evenodd") { gp.FillMode = FillMode.Alternate; } else { gp.FillMode = FillMode.Winding; } return(gp); }
protected override void OnPaint(PaintEventArgs e) { //ref: http://www.windowsdevcenter.com/pub/a/dotnet/2002/03/18/customcontrols.html?page=2 Graphics graphics = e.Graphics; int penWidth = 4; Pen pen = new Pen(Color.Black, penWidth); Pen penOrange = new Pen(Color.Orange, 2); int fontHeight = 10; Font font = new Font("Arial", fontHeight); int fontHeight2 = 20; Font font2 = new Font("Arial", fontHeight2); SolidBrush brush = new SolidBrush(backgroundColor); graphics.FillRectangle(brush, 0, 0, Width, Height); SolidBrush textBrush = new SolidBrush(Color.Black); SolidBrush textBrush2 = new SolidBrush(Color.Red); //graphics.DrawEllipse(pen, (int)penWidth / 2, //(int)penWidth / 2, Width - penWidth, Height - penWidth); graphics.DrawRectangle(pen, 0, 0, Width, Height); Rectangle rect = new Rectangle(0, 0, Width, Height); Rectangle rect1 = new Rectangle(10, 10, Width - 20, Height - 20); GraphicsPath RoundedRect(Rectangle bounds, int radius) { int diameter = radius * 2; Size size = new Size(diameter, diameter); Rectangle arc = new Rectangle(bounds.Location, size); GraphicsPath path = new GraphicsPath(); if (radius == 0) { path.AddRectangle(bounds); return(path); } // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = bounds.Right - diameter; path.AddArc(arc, 270, 90); // bottom right arc arc.Y = bounds.Bottom - diameter; path.AddArc(arc, 0, 90); // bottom left arc arc.X = bounds.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); return(path); } graphics.DrawPath(pen, RoundedRect(rect1, 12)); graphics.DrawString(LabelBouton, font, textBrush, Width / 2 - fontHeight, Height / 2 - fontHeight); Pen pen2 = new Pen(Color.Blue, 1); SolidBrush brushValeur = new SolidBrush(Color.Red); SolidBrush brushValeurWhite = new SolidBrush(Color.White); SolidBrush brushValeurBlack = new SolidBrush(Color.Black); SolidBrush brushValeurres = new SolidBrush(Color.Red); // MessageBox.Show(Width.ToString()); double valeurWid = ((Width * 0.80)); // double beginingPoint = (Width * 0.10); double fin = Width * 0.80; //MessageBox.Show(beginingPoint.ToString()); graphics.FillRectangle(brushValeurWhite, (float)(beginingPoint), (float)(Height * 0.60), (float)fin, 12); double f = 0; // MessageBox.Show(Width.ToString()+"widith * 80"+ Width* 0.80+" begining "+beginingPoint +" fin : "+fin); double incremntationPar = Width / 5; for (double i = beginingPoint; i <= (float)(Width * 0.90); i += incremntationPar) { // create the line sepratores graphics.FillRectangle(brushValeurBlack, (float)i, (float)(Height * 0.60) - 23, 3, (float)(Height * 0.12)); graphics.FillRectangle(brushValeurBlack, (float)(i) / 3, (float)(Height * 0.65) - 23, 1, (float)(Height * 0.06)); graphics.DrawString((f).ToString(), font, textBrush, (float)i - 10, (float)(Height * 0.60) - 50); if (f <= Valeur_Max) { f += Valeur_Max / 4; } } for (int i = 0; i <= ((Mesure * fin) / Valeur_Max); i++) { graphics.DrawEllipse(penOrange, (float)(beginingPoint + i) - 14, (float)(Height * 0.60) + 2 - 14, 14 + 14, 14 + 14); Thread.Sleep(50); } }
/// <summary> /// This gets called to instruct the element to draw itself in the appropriate spot of the graphics object /// </summary> /// <param name="g">The graphics object to draw to</param> /// <param name="printing">boolean, true if printing to the actual paper/document, false if drawing as a control</param> protected override void Draw(Graphics g, bool printing, bool export, int x, int y) { if (!Visible) { return; } var gp = new GraphicsPath(); Point[] pts; bool custom = _northArrowStyle == NorthArrowStyle.ArrowNS; int width = custom ? 30 : 100; int height = custom ? 250 : 100; var m = new Matrix(SizeF.Width / width, 0F, 0F, SizeF.Height / height, x, y); m.RotateAt(_rotation, new PointF(width / 2f, height / 2f), MatrixOrder.Prepend); if (_northArrowStyle == NorthArrowStyle.ArrowNS) { m = new Matrix(1f, 0f, 0f, 1f, x, y); m.RotateAt(_rotation, new PointF(width / 2f, height / 2f), MatrixOrder.Prepend); } var mypen = new Pen(_color, 2F); var fillBrush = new SolidBrush(_color); mypen.LineJoin = LineJoin.Round; mypen.StartCap = LineCap.Round; mypen.EndCap = LineCap.Round; //All north arrows are defined as a graphics path in 100x100 size which is then scaled to fit the rectangle of the element switch (_northArrowStyle) { case NorthArrowStyle.ArrowNS: var thinPen = new Pen(_color, 1F); gp.AddLine(0, 10, 5, 0); gp.StartFigure(); gp.AddLine(5, 0, 10, 10); gp.StartFigure(); gp.AddLine(0, 10, 4, 10); gp.StartFigure(); gp.AddLine(6, 10, 10, 10); gp.StartFigure(); gp.AddLine(4, 10, 4, SizeF.Height - 65); gp.StartFigure(); gp.AddLine(6, 10, 6, SizeF.Height - 65); gp.StartFigure(); gp.AddLine(4, SizeF.Height - 65, 2, SizeF.Height - 60); gp.StartFigure(); gp.AddLine(6, SizeF.Height - 65, 8, SizeF.Height - 60); gp.StartFigure(); gp.AddLine(2, SizeF.Height - 60, 2, SizeF.Height - 50); gp.StartFigure(); gp.AddLine(8, SizeF.Height - 60, 8, SizeF.Height - 50); gp.StartFigure(); gp.AddLine(2, SizeF.Height - 50, 5, SizeF.Height - 53); gp.StartFigure(); gp.AddLine(5, SizeF.Height - 53, 8, SizeF.Height - 50); gp.StartFigure(); m.Translate(2, 14); gp.Transform(m); g.DrawPath(thinPen, gp); gp.Reset(); gp.AddString("N", FontFamily.GenericSansSerif, (int)FontStyle.Regular, 12.0f, new Point { X = 0, Y = 0 }, StringFormat.GenericDefault); gp.AddString("S", FontFamily.GenericSansSerif, (int)FontStyle.Regular, 12.0f, new Point { X = 0, Y = (int)(SizeF.Height - 36) }, StringFormat.GenericDefault); m.Translate(-2, -14); gp.Transform(m); g.DrawPath(thinPen, gp); break; case (NorthArrowStyle.BlackArrow): gp.AddLine(50, 5, 5, 50); gp.AddLine(5, 50, 30, 50); gp.AddLine(30, 50, 30, 95); gp.AddLine(30, 95, 70, 95); gp.AddLine(70, 95, 70, 50); gp.AddLine(70, 50, 95, 50); gp.CloseFigure(); gp.Transform(m); g.DrawPath(mypen, gp); g.FillPath(fillBrush, gp); //N gp = new GraphicsPath(); gp.AddLine(40, 80, 40, 45); gp.StartFigure(); gp.AddLine(40, 45, 60, 80); gp.StartFigure(); gp.AddLine(60, 80, 60, 45); gp.StartFigure(); mypen.Color = Color.White; mypen.Width = SizeF.Width / 20; gp.Transform(m); g.DrawPath(mypen, gp); break; case (NorthArrowStyle.Default): //draw the outline DrawOutline(gp); gp.CloseFigure(); //Draw the N gp.AddLine(45, 57, 45, 43); gp.StartFigure(); gp.AddLine(45, 43, 55, 57); gp.StartFigure(); gp.AddLine(55, 57, 55, 43); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); //Draw the top arrow gp = new GraphicsPath(); gp.AddLine(50, 5, 60, 40); gp.AddBezier(60, 40, 55, 35, 45, 35, 40, 40); gp.CloseFigure(); gp.Transform(m); g.DrawPath(mypen, gp); g.FillPath(fillBrush, gp); break; case (NorthArrowStyle.CenterStar): //Outline DrawOutline(gp); gp.AddBezier(40F, 40F, 45F, 35F, 55F, 35F, 60f, 40F); gp.AddLine(60, 40, 50, 5); gp.CloseFigure(); //N gp.AddLine(47, 33, 47, 20); gp.StartFigure(); gp.AddLine(47, 20, 53, 33); gp.StartFigure(); gp.AddLine(53, 33, 53, 20); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); //Draw the center circle gp = new GraphicsPath(); gp.AddLine(30, 30, 40, 50); gp.AddLine(40, 50, 30, 70); gp.AddLine(30, 70, 50, 60); gp.AddLine(50, 60, 70, 70); gp.AddLine(70, 70, 60, 50); gp.AddLine(60, 50, 70, 30); gp.AddLine(70, 30, 50, 40); gp.CloseFigure(); gp.Transform(m); g.DrawPath(mypen, gp); g.FillPath(fillBrush, gp); break; case (NorthArrowStyle.TriangleN): pts = new Point[3]; pts[0] = new Point(50, 5); pts[1] = new Point(5, 95); pts[2] = new Point(95, 95); gp.AddLines(pts); gp.CloseFigure(); gp.AddLine(40, 80, 40, 45); gp.StartFigure(); gp.AddLine(40, 45, 60, 80); gp.StartFigure(); gp.AddLine(60, 80, 60, 45); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); break; case (NorthArrowStyle.TriangleHat): pts = new Point[3]; pts[0] = new Point(50, 5); pts[1] = new Point(5, 60); pts[2] = new Point(95, 60); gp.AddLines(pts); gp.CloseFigure(); gp.AddLine(5, 95, 5, 65); gp.StartFigure(); gp.AddLine(5, 65, 95, 95); gp.StartFigure(); gp.AddLine(95, 95, 95, 65); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); break; case (NorthArrowStyle.ArrowN): pts = new Point[3]; pts[0] = new Point(5, 25); pts[1] = new Point(50, 5); pts[2] = new Point(95, 25); gp.AddLines(pts); gp.CloseFigure(); gp.AddLine(50, 25, 50, 95); gp.StartFigure(); gp.AddLine(5, 80, 5, 45); gp.StartFigure(); gp.AddLine(5, 45, 95, 80); gp.StartFigure(); gp.AddLine(95, 80, 95, 45); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); break; } gp.Dispose(); }
public override void OnMouseMove(PointF location, Keys keys, MouseButtons buttons) { base.OnMouseMove(location, keys, buttons); if (mouseDown) { if (Project.SelectedLayer is IEditable) { if (Type == ShapeType.FreeForm) { workingPath.AddLine(mouseInit, location); path.Dispose(); path = workingPath.Clone() as GraphicsPath; path.CloseFigure(); mouseInit = location; } else if (Type == ShapeType.Polygon) { path.Dispose(); path = workingPath.Clone() as GraphicsPath; path.AddLine(mouseInit, location); path.CloseFigure(); currMouse = location; } else { path.Dispose(); path = new GraphicsPath(); if (Type == ShapeType.Line) { path.AddLine(mouseInit, location); } else { var pos = new PointF( Math.Min(mouseInit.X, location.X), Math.Min(mouseInit.Y, location.Y) ); var size = new SizeF( Math.Abs(mouseInit.X - location.X), Math.Abs(mouseInit.Y - location.Y) ); if (keys.HasFlag(Keys.Shift)) { var min = Math.Min(size.Width, size.Height); if (location.X < mouseInit.X && size.Width > min) { pos.X += size.Width - min; } if (location.Y < mouseInit.Y && size.Height > min) { pos.Y += size.Height - min; } size = new SizeF(min, min); } switch (Type) { case ShapeType.Rectangle: path.AddRectangle(new RectangleF(pos, size)); break; case ShapeType.Ellipse: path.AddEllipse(new RectangleF(pos, size)); break; } } } Invalidate(); } } }
private GraphicsPath RoundRectangle(Rectangle r, int radius, GroupBoxCorners corners) { GraphicsPath path = new GraphicsPath(); if (r.Width <= 0 | r.Height <= 0) return path; int d = radius * 2; int nw = ((corners & GroupBoxCorners.NorthWest) == GroupBoxCorners.NorthWest ? d : 0); int ne = ((corners & GroupBoxCorners.NorthEast) == GroupBoxCorners.NorthEast ? d : 0); int se = ((corners & GroupBoxCorners.SouthEast) == GroupBoxCorners.SouthEast ? d : 0); int sw = ((corners & GroupBoxCorners.SouthWest) == GroupBoxCorners.SouthWest ? d : 0); path.AddLine(r.Left + nw, r.Top, r.Right - ne, r.Top); if (ne > 0) { path.AddArc(Rectangle.FromLTRB(r.Right - ne, r.Top, r.Right, r.Top + ne), -90, 90); } path.AddLine(r.Right, r.Top + ne, r.Right, r.Bottom - se); if (se > 0) { path.AddArc(Rectangle.FromLTRB(r.Right - se, r.Bottom - se, r.Right, r.Bottom), 0, 90); } path.AddLine(r.Right - se, r.Bottom, r.Left + sw, r.Bottom); if (sw > 0) { path.AddArc(Rectangle.FromLTRB(r.Left, r.Bottom - sw, r.Left + sw, r.Bottom), 90, 90); } path.AddLine(r.Left, r.Bottom - sw, r.Left, r.Top + nw); if (nw > 0) { path.AddArc(Rectangle.FromLTRB(r.Left, r.Top, r.Left + nw, r.Top + nw), 180, 90); } path.CloseFigure(); return path; }
public virtual void Draw(ICanvas canvas, RectangleF unitrect) { try { Pen pen = null; if (Type == LineType.PointLine) { pen = new Pen(Color, Width); } else if (Type == LineType.Line) { pen = new Pen(Color, Width); } else { pen = new Pen(Color, 1); pen.DashStyle = DashStyle.Custom; pen.DashPattern = new float[] { 10f, 10f }; } if (UseRoute) { pen.Color = Color.DeepPink; pen.DashStyle = DashStyle.Custom; pen.DashPattern = new float[] { 1f, 1f }; } if (Type == LineType.PointLine) { GraphicsPath hPath = new GraphicsPath(); float ScrtopY = canvas.ToScreen(0); float ScrtopX = canvas.ToScreen(0); float ScrRightX = canvas.ToScreen(0.03); float ScrRightY = canvas.ToScreen(-0.08); float ScrLeftX = canvas.ToScreen(-0.03); float ScrLeftY = canvas.ToScreen(-0.08); hPath.AddLine(new PointF(ScrtopX, ScrLeftY), new PointF(ScrRightX, ScrRightY)); hPath.AddLine(new PointF(ScrRightX, ScrRightY), new PointF(ScrtopX, ScrtopY)); hPath.AddLine(new PointF(ScrtopX, ScrtopY), new PointF(ScrLeftX, ScrLeftY)); hPath.CloseFigure(); CustomLineCap HookCap = new CustomLineCap(hPath, null); pen.CustomEndCap = HookCap; } else { pen.EndCap = System.Drawing.Drawing2D.LineCap.Round; } pen.StartCap = System.Drawing.Drawing2D.LineCap.Round; canvas.DrawLine(canvas, pen, m_p1, m_p2); if (Highlighted) { canvas.DrawLine(canvas, DrawUtils.SelectedPen, m_p1, m_p2); } if (Selected) { canvas.DrawLine(canvas, DrawUtils.SelectedPen, m_p1, m_p2); if (m_p1.IsEmpty == false) { DrawUtils.DrawNode(canvas, m_p1); } if (m_p2.IsEmpty == false) { DrawUtils.DrawNode(canvas, m_p2); } } } catch (Exception ex) { throw ex; } }
/// <summary> /// /// </summary> /// <param name="Rect"></param> /// <returns></returns> private GraphicsPath CreateCloseFlagPath(Rectangle Rect) { PointF centerPoint = new PointF( Rect.X + Rect.Width / 2.0f, Rect.Y + Rect.Height / 2.0f); GraphicsPath path = new GraphicsPath(); path.AddLine( centerPoint.X, centerPoint.Y - 2, centerPoint.X - 2, centerPoint.Y - 4); path.AddLine( centerPoint.X - 2, centerPoint.Y - 4, centerPoint.X - 6, centerPoint.Y - 4); path.AddLine( centerPoint.X - 6, centerPoint.Y - 4, centerPoint.X - 2, centerPoint.Y); path.AddLine( centerPoint.X - 2, centerPoint.Y, centerPoint.X - 6, centerPoint.Y + 4); path.AddLine( centerPoint.X - 6, centerPoint.Y + 4, centerPoint.X - 2, centerPoint.Y + 4); path.AddLine( centerPoint.X - 2, centerPoint.Y + 4, centerPoint.X, centerPoint.Y + 2); path.AddLine( centerPoint.X, centerPoint.Y + 2, centerPoint.X + 2, centerPoint.Y + 4); path.AddLine( centerPoint.X + 2, centerPoint.Y + 4, centerPoint.X + 6, centerPoint.Y + 4); path.AddLine( centerPoint.X + 6, centerPoint.Y + 4, centerPoint.X + 2, centerPoint.Y); path.AddLine( centerPoint.X + 2, centerPoint.Y, centerPoint.X + 6, centerPoint.Y - 4); path.AddLine( centerPoint.X + 6, centerPoint.Y - 4, centerPoint.X + 2, centerPoint.Y - 4); path.CloseFigure(); return(path); }
public static Image CreateTornEdge(Image sourceImage, int toothHeight, int horizontalToothRange, int verticalToothRange, AnchorStyles sides) { Image result = sourceImage.CreateEmptyBitmap(); using (GraphicsPath path = new GraphicsPath()) { Random random = new Random(); int horizontalRegions = sourceImage.Width / horizontalToothRange; int verticalRegions = sourceImage.Height / verticalToothRange; Point previousEndingPoint = new Point(horizontalToothRange, random.Next(1, toothHeight)); Point newEndingPoint; if (sides.HasFlag(AnchorStyles.Top)) { for (int i = 0; i < horizontalRegions; i++) { int x = previousEndingPoint.X + horizontalToothRange; int y = random.Next(1, toothHeight); newEndingPoint = new Point(x, y); path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } } else { previousEndingPoint = new Point(0, 0); newEndingPoint = new Point(sourceImage.Width, 0); path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } if (sides.HasFlag(AnchorStyles.Right)) { for (int i = 0; i < verticalRegions; i++) { int x = sourceImage.Width - random.Next(1, toothHeight); int y = previousEndingPoint.Y + verticalToothRange; newEndingPoint = new Point(x, y); path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } } else { previousEndingPoint = new Point(sourceImage.Width, 0); newEndingPoint = new Point(sourceImage.Width, sourceImage.Height); path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } if (sides.HasFlag(AnchorStyles.Bottom)) { for (int i = 0; i < horizontalRegions; i++) { int x = previousEndingPoint.X - horizontalToothRange; int y = sourceImage.Height - random.Next(1, toothHeight); newEndingPoint = new Point(x, y); path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } } else { previousEndingPoint = new Point(sourceImage.Width, sourceImage.Height); newEndingPoint = new Point(0, sourceImage.Height); path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } if (sides.HasFlag(AnchorStyles.Left)) { for (int i = 0; i < verticalRegions; i++) { int x = random.Next(1, toothHeight); int y = previousEndingPoint.Y - verticalToothRange; newEndingPoint = new Point(x, y); path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } } else { previousEndingPoint = new Point(0, sourceImage.Height); newEndingPoint = new Point(0, 0); path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } path.CloseFigure(); using (Graphics graphics = Graphics.FromImage(result)) { graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; // Draw the created figure with the original image by using a TextureBrush so we have anti-aliasing using (Brush brush = new TextureBrush(sourceImage)) { graphics.FillPath(brush, path); } } } return(result); }
/// <summary> /// /// </summary> /// <param name="Rect"></param> /// <param name="Maximize"></param> /// <returns></returns> private GraphicsPath CreateMaximizeFlafPath( Rectangle Rect, bool Maximize) { PointF centerPoint = new PointF( Rect.X + Rect.Width / 2.0f, Rect.Y + Rect.Height / 2.0f); GraphicsPath path = new GraphicsPath(); if (Maximize) { path.AddLine( centerPoint.X - 3, centerPoint.Y - 3, centerPoint.X - 6, centerPoint.Y - 3); path.AddLine( centerPoint.X - 6, centerPoint.Y - 3, centerPoint.X - 6, centerPoint.Y + 5); path.AddLine( centerPoint.X - 6, centerPoint.Y + 5, centerPoint.X + 3, centerPoint.Y + 5); path.AddLine( centerPoint.X + 3, centerPoint.Y + 5, centerPoint.X + 3, centerPoint.Y + 1); path.AddLine( centerPoint.X + 3, centerPoint.Y + 1, centerPoint.X + 6, centerPoint.Y + 1); path.AddLine( centerPoint.X + 6, centerPoint.Y + 1, centerPoint.X + 6, centerPoint.Y - 6); path.AddLine( centerPoint.X + 6, centerPoint.Y - 6, centerPoint.X - 3, centerPoint.Y - 6); path.CloseFigure(); path.AddRectangle(new RectangleF( centerPoint.X - 4, centerPoint.Y, 5, 3)); path.AddLine( centerPoint.X - 1, centerPoint.Y - 4, centerPoint.X + 4, centerPoint.Y - 4); path.AddLine( centerPoint.X + 4, centerPoint.Y - 4, centerPoint.X + 4, centerPoint.Y - 1); path.AddLine( centerPoint.X + 4, centerPoint.Y - 1, centerPoint.X + 3, centerPoint.Y - 1); path.AddLine( centerPoint.X + 3, centerPoint.Y - 1, centerPoint.X + 3, centerPoint.Y - 3); path.AddLine( centerPoint.X + 3, centerPoint.Y - 3, centerPoint.X - 1, centerPoint.Y - 3); path.CloseFigure(); } else { path.AddRectangle(new RectangleF( centerPoint.X - 6, centerPoint.Y - 4, 12, 8)); path.AddRectangle(new RectangleF( centerPoint.X - 3, centerPoint.Y - 1, 6, 3)); } return(path); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (IndicatorSizeValue > 0) { Region ControlRegion = null; using (GraphicsPath Path = new GraphicsPath()) { Rectangle OffsetRectangle = new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height); int IndicatorSizeValue2 = (IndicatorSizeValue * 2); int IndicatorStart = 0; if ((IndicatorAlignmentValue == TabAlignment.Left) || (IndicatorAlignmentValue == TabAlignment.Right)) { IndicatorStart = this.Height; } else { IndicatorStart = this.Width; } IndicatorStart -= IndicatorSizeValue2; IndicatorStart = ((IndicatorStart * IndicatorLocationValue) / 100); Path.FillMode = FillMode.Winding; Path.StartFigure(); int IndicatorMiddle = (IndicatorStart + IndicatorSizeValue); int IndicatorEnd = (IndicatorStart + IndicatorSizeValue2); if (IndicatorAlignmentValue == TabAlignment.Left) { OffsetRectangle.X += IndicatorSizeValue; OffsetRectangle.Width -= IndicatorSizeValue; Path.AddLine(OffsetRectangle.Left, IndicatorStart, OffsetRectangle.Left, IndicatorEnd); Path.AddLine(OffsetRectangle.Left, IndicatorEnd, OffsetRectangle.Left - IndicatorSizeValue, IndicatorMiddle); Path.AddLine(OffsetRectangle.Left - IndicatorSizeValue, IndicatorMiddle, OffsetRectangle.Left, IndicatorStart); } else if (IndicatorAlignmentValue == TabAlignment.Right) { OffsetRectangle.Width -= IndicatorSizeValue; Path.AddLine(OffsetRectangle.Right, IndicatorStart, OffsetRectangle.Right + IndicatorSizeValue, IndicatorMiddle); Path.AddLine(OffsetRectangle.Right + IndicatorSizeValue, IndicatorMiddle, OffsetRectangle.Right, IndicatorEnd); Path.AddLine(OffsetRectangle.Right, IndicatorEnd, OffsetRectangle.Right, IndicatorStart); } else if (IndicatorAlignmentValue == TabAlignment.Top) { OffsetRectangle.Y += IndicatorSizeValue; OffsetRectangle.Height -= IndicatorSizeValue; Path.AddLine(IndicatorStart, OffsetRectangle.Top, IndicatorMiddle, OffsetRectangle.Top - IndicatorSizeValue); Path.AddLine(IndicatorMiddle, OffsetRectangle.Top - IndicatorSizeValue, IndicatorEnd, OffsetRectangle.Top); Path.AddLine(IndicatorEnd, OffsetRectangle.Top, IndicatorStart, OffsetRectangle.Top); } else if (IndicatorAlignmentValue == TabAlignment.Bottom) { OffsetRectangle.Height -= IndicatorSizeValue; Path.AddLine(IndicatorStart, OffsetRectangle.Bottom, IndicatorEnd, OffsetRectangle.Bottom); Path.AddLine(IndicatorEnd, OffsetRectangle.Bottom, IndicatorMiddle, OffsetRectangle.Bottom + IndicatorSizeValue); Path.AddLine(IndicatorMiddle, OffsetRectangle.Bottom + IndicatorSizeValue, IndicatorStart, OffsetRectangle.Bottom); } Path.CloseFigure(); Region TabRegion = new Region(Path); ControlRegion = new Region(OffsetRectangle); ControlRegion.Union(TabRegion); } this.Region = ControlRegion; } }
public void StraightConnection_PaintOneRange( Graphics g, Processed2DPlotData pdata, PlotRange range, IPlotArea layer, Processed2DPlotData previousData) { PointF[] linePoints = pdata.PlotPointsInAbsoluteLayerCoordinates; var linepts = new PointF[range.Length]; Array.Copy(linePoints, range.LowerBound, linepts, 0, range.Length); // Extract int lastIdx = range.Length - 1; // Try to find points with a similar x value on otherlinepoints double firstLogicalX = layer.XAxis.PhysicalVariantToNormal(pdata.GetXPhysical(range.OriginalFirstPoint)); double lastLogicalX = layer.XAxis.PhysicalVariantToNormal(pdata.GetXPhysical(range.OriginalLastPoint)); double minDistanceToFirst = double.MaxValue; double minDistanceToLast = double.MaxValue; int minIdxFirst = -1; int minIdxLast = -1; foreach (var rangeP in previousData.RangeList) { for (int i = rangeP.LowerBound; i < rangeP.UpperBound; ++i) { double logicalX = layer.XAxis.PhysicalVariantToNormal(previousData.GetXPhysical(i + rangeP.OffsetToOriginal)); if (Math.Abs(logicalX - firstLogicalX) < minDistanceToFirst) { minDistanceToFirst = Math.Abs(logicalX - firstLogicalX); minIdxFirst = i; } if (Math.Abs(logicalX - lastLogicalX) < minDistanceToLast) { minDistanceToLast = Math.Abs(logicalX - lastLogicalX); minIdxLast = i; } } } // if nothing found, use the outmost boundaries of the plot points of the other data item if (minIdxFirst < 0) { minIdxFirst = 0; } if (minIdxLast < 0) { minIdxLast = previousData.PlotPointsInAbsoluteLayerCoordinates.Length - 1; } var otherLinePoints = new PointF[minIdxLast + 1 - minIdxFirst]; Array.Copy(previousData.PlotPointsInAbsoluteLayerCoordinates, minIdxFirst, otherLinePoints, 0, otherLinePoints.Length); Array.Reverse(otherLinePoints); // now paint this var gp = new GraphicsPath(); var layerSize = layer.Size; gp.StartFigure(); gp.AddLines(linepts); gp.AddLines(otherLinePoints); gp.CloseFigure(); if (_fillBrush.IsVisible) { g.FillPath(_fillBrush, gp); } if (null != _framePen) { g.DrawPath(_framePen, gp); } gp.Reset(); } // end function PaintOneRange
protected GraphicsPath ParsePath() { GraphicsPath result = new GraphicsPath(FillMode.Alternate); PointF lastPoint = new PointF(); Regex regex = new Regex(@"[a-zA-Z][-0-9\.,-0-9\. ]*"); MatchCollection matches = regex.Matches(Data); foreach (Match match in matches) { char cmd = match.Value[0]; PointF[] points; string pointsStr = match.Value.Substring(1).Trim(); if (pointsStr.Length > 0) { string[] txtpoints = pointsStr.Split(new char[] { ',', ' ' }); if (txtpoints.Length == 1) { points = new PointF[1]; points[0].X = (float)TypeConverter.Convert(txtpoints[0], typeof(float)); } else { int c = txtpoints.Length / 2; points = new PointF[c]; for (int i = 0; i < c; i++) { points[i].X = (float)TypeConverter.Convert(txtpoints[i * 2], typeof(float)); if (i + 1 < txtpoints.Length) { points[i].Y = (float)TypeConverter.Convert(txtpoints[i * 2 + 1], typeof(float)); } } } } else { points = new PointF[] {} }; switch (cmd) { case 'm': { //Relative origin PointF point = points[0]; lastPoint = new PointF(lastPoint.X + point.X, lastPoint.Y + point.Y); result.StartFigure(); } break; case 'M': { //Absolute origin lastPoint = points[0]; result.StartFigure(); } break; case 'L': //Absolute Line foreach (PointF t in points) { result.AddLine(lastPoint, t); lastPoint = t; } break; case 'l': //Relative Line for (int i = 0; i < points.Length; ++i) { points[i].X += lastPoint.X; points[i].Y += lastPoint.Y; result.AddLine(lastPoint, points[i]); lastPoint = points[i]; } break; case 'H': { //Horizontal line to absolute X PointF point1 = new PointF(points[0].X, lastPoint.Y); result.AddLine(lastPoint, point1); lastPoint = new PointF(point1.X, point1.Y); } break; case 'h': { //Horizontal line to relative X PointF point1 = new PointF(lastPoint.X + points[0].X, lastPoint.Y); result.AddLine(lastPoint, point1); lastPoint = new PointF(point1.X, point1.Y); } break; case 'V': { //Vertical line to absolute y PointF point1 = new PointF(lastPoint.X, points[0].X); result.AddLine(lastPoint, point1); lastPoint = new PointF(point1.X, point1.Y); } break; case 'v': { //Vertical line to relative y PointF point1 = new PointF(lastPoint.X, lastPoint.Y + points[0].X); result.AddLine(lastPoint, point1); lastPoint = new PointF(point1.X, point1.Y); } break; case 'C': //Quadratic Bezier curve command C21,17,17,21,13,21 for (int i = 0; i < points.Length; i += 3) { result.AddBezier(lastPoint, points[i], points[i + 1], points[i + 2]); lastPoint = points[i + 2]; } break; case 'c': //Quadratic Bezier curve command for (int i = 0; i < points.Length; i += 3) { points[i].X += lastPoint.X; points[i].Y += lastPoint.Y; result.AddBezier(lastPoint, points[i], points[i + 1], points[i + 2]); lastPoint = points[i + 2]; } break; case 'F': //Set fill mode command if (points[0].X == 0.0f) { //the EvenOdd fill rule //Rule that determines whether a point is in the fill region by drawing a ray //from that point to infinity in any direction and counting the number of path //segments within the given shape that the ray crosses. If this number is odd, //the point is inside; if even, the point is outside. result.FillMode = FillMode.Alternate; } else if (points[0].X == 1.0f) { //the Nonzero fill rule. //Rule that determines whether a point is in the fill region of the //path by drawing a ray from that point to infinity in any direction //and then examining the places where a segment of the shape crosses //the ray. Starting with a count of zero, add one each time a segment //crosses the ray from left to right and subtract one each time a path //segment crosses the ray from right to left. After counting the crossings, //if the result is zero then the point is outside the path. Otherwise, it is inside. result.FillMode = FillMode.Winding; } break; case 'z': result.CloseFigure(); break; } } return(result); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { cellStyle.Alignment = DataGridViewContentAlignment.TopLeft; base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); if (active) { var mode = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.AntiAlias; var rec = new Rectangle(cellBounds.Left + cellStyle.Padding.Left, cellBounds.Top + cellStyle.Padding.Top, cellBounds.Width - cellStyle.Padding.Left - cellStyle.Padding.Right, CELL_HEIGHT); var innerRec = new Rectangle(rec.Location, rec.Size); innerRec.Inflate(-1, -1); using (GraphicsPath path = new GraphicsPath()) { int diameter = 4; var arc = new Rectangle(rec.Location, new Size(diameter, diameter)); //top left corner path.AddArc(arc, 180, 90); // top right corner arc.X = rec.Right - diameter; path.AddArc(arc, 270, 90); // bottom right corner arc.Y = rec.Bottom - diameter; path.AddArc(arc, 0, 90); // bottom left corner arc.X = rec.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); using (var brush = new LinearGradientBrush(rec, BUTTON_FACE_TOP, BUTTON_FACE_BOTTOM, LinearGradientMode.Vertical)) { ColorBlend cb = new ColorBlend(); cb.Positions = new[] { 0, 1 / 2f, 1 / 2f, 1 }; cb.Colors = new[] { BUTTON_FACE_TOP, BUTTON_FACE_MIDDLE_TOP, BUTTON_FACE_MIDDLE_BOTTOM, BUTTON_FACE_BOTTOM }; brush.InterpolationColors = cb; graphics.FillPath(brush, path); } using (Pen pen = new Pen(BUTTON_BORDER_OUTER, 1)) graphics.DrawPath(pen, path); } using (GraphicsPath path = new GraphicsPath()) { int diameter = 4; var arc = new Rectangle(innerRec.Location, new Size(diameter, diameter)); //top left corner path.AddArc(arc, 180, 90); // top right corner arc.X = innerRec.Right - diameter; path.AddArc(arc, 270, 90); // bottom right corner arc.Y = innerRec.Bottom - diameter; path.AddArc(arc, 0, 90); // bottom left corner arc.X = innerRec.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); using (Pen pen = new Pen(BUTTON_BORDER_INNER, 1)) graphics.DrawPath(pen, path); } using (var font = new Font(DataGridView.DefaultCellStyle.Font, FontStyle.Regular)) graphics.DrawString(value as string, font, SystemBrushes.ControlText, cellBounds); using (Pen pen = new Pen(BUTTON_BORDER_OUTER, 1)) graphics.DrawLine(pen, cellBounds.Right - cellStyle.Padding.Right - SPLITTER_FROM_RIGHT, cellBounds.Top + cellStyle.Padding.Top + 2, cellBounds.Right - cellStyle.Padding.Right - SPLITTER_FROM_RIGHT, cellBounds.Top + cellStyle.Padding.Top + CELL_HEIGHT - 2); //reset graphics mode graphics.SmoothingMode = mode; } var img = Properties.Resources.expanded_triangle; graphics.DrawImage(img, cellBounds.Right - cellStyle.Padding.Right - img.Width - (SPLITTER_FROM_RIGHT - img.Width) / 2, cellBounds.Top + (CELL_HEIGHT - img.Height) / 2); }
/// <summary> /// Handles drawing of editing features /// </summary> /// <param name="e">The drawing args</param> protected override void OnDraw(MapDrawArgs e) { Point mouseTest = Map.PointToClient(Control.MousePosition); bool hasMouse = Map.ClientRectangle.Contains(mouseTest); Pen bluePen = new Pen(Color.Blue, 2F); Pen redPen = new Pen(Color.Red, 3F); Brush redBrush = new SolidBrush(Color.Red); List <Point> points = new List <Point>(); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Brush blue = new SolidBrush(Color.FromArgb(60, 0, 0, 255)); if (_previousParts != null && _previousParts.Count > 0) { GraphicsPath previous = new GraphicsPath { FillMode = FillMode.Winding }; List <Point> allPoints = new List <Point>(); foreach (List <Coordinate> part in _previousParts) { List <Point> prt = new List <Point>(); foreach (Coordinate c in part) { prt.Add(Map.ProjToPixel(c)); } previous.AddLines(prt.ToArray()); allPoints.AddRange(prt); if (_areaMode) { previous.CloseFigure(); } previous.StartFigure(); } if (_areaMode && _coordinates != null) { List <Point> fillPts = new List <Point>(); if ((!_standBy && _coordinates.Count > 2) || _coordinates.Count > 3) { foreach (Coordinate c in _coordinates) { fillPts.Add(Map.ProjToPixel(c)); } if (!_standBy && hasMouse) { fillPts.Add(_mousePosition); } previous.AddLines(fillPts.ToArray()); previous.CloseFigure(); } } if (allPoints.Count > 1) { e.Graphics.DrawPath(bluePen, previous); if (_areaMode) { e.Graphics.FillPath(blue, previous); } } foreach (Point pt in allPoints) { e.Graphics.FillRectangle(redBrush, new Rectangle(pt.X - 2, pt.Y - 2, 4, 4)); } } if (_coordinates != null) { foreach (Coordinate coord in _coordinates) { points.Add(Map.ProjToPixel(coord)); } if (points.Count > 1) { e.Graphics.DrawLines(bluePen, points.ToArray()); foreach (Point pt in points) { e.Graphics.FillRectangle(redBrush, new Rectangle(pt.X - 2, pt.Y - 2, 4, 4)); } } if (points.Count > 0 && _standBy == false && hasMouse) { e.Graphics.DrawLine(redPen, points[points.Count - 1], _mousePosition); if (_areaMode && points.Count > 1) { e.Graphics.DrawLine(redPen, points[0], _mousePosition); } } if (points.Count > 1 && _areaMode && (_previousParts == null || _previousParts.Count == 0)) { if (hasMouse && !_standBy) { points.Add(_mousePosition); } if (points.Count > 2) { e.Graphics.FillPolygon(blue, points.ToArray()); } } } bluePen.Dispose(); redPen.Dispose(); redBrush.Dispose(); blue.Dispose(); base.OnDraw(e); }
protected virtual void OnPaintForeground(PaintEventArgs e) { this.MinimumSize = new Size(0, GetPreferredSize(Size.Empty).Height); Color borderColor, foreColor; if (isHovered && !isPressed && Enabled) { foreColor = MetroPaint.ForeColor.ComboBox.Hover(Theme); borderColor = MetroPaint.GetStyleColor(Style); } else if (isHovered && isPressed && Enabled) { foreColor = MetroPaint.ForeColor.ComboBox.Press(Theme); borderColor = MetroPaint.GetStyleColor(Style); } else if (!Enabled) { foreColor = MetroPaint.ForeColor.ComboBox.Disabled(Theme); borderColor = MetroPaint.BorderColor.ComboBox.Disabled(Theme); } else { foreColor = MetroPaint.ForeColor.ComboBox.Normal(Theme); borderColor = MetroPaint.BorderColor.ComboBox.Normal(Theme); } using (Pen p = new Pen(borderColor)) { int cornerRadius = 3; p.Width = 1; //边框工作区 Rectangle rect = this.ClientRectangle; GraphicsPath Rect = new GraphicsPath(); // 添加圆弧 Rect.AddArc(0, 0, cornerRadius * 2, cornerRadius * 2, 180, 90); Rect.AddArc(rect.Width - cornerRadius * 2 - 1, 0, cornerRadius * 2, cornerRadius * 2, 270, 90); Rect.AddArc(rect.Width - cornerRadius * 2 - 1, rect.Height - cornerRadius * 2 - 1, cornerRadius * 2, cornerRadius * 2, 0, 90); Rect.AddArc(0, rect.Height - cornerRadius * 2 - 1, cornerRadius * 2, cornerRadius * 2, 90, 90); Rect.CloseFigure(); e.Graphics.DrawPath(p, Rect); } using (SolidBrush b = new SolidBrush(foreColor)) { e.Graphics.FillPolygon(b, new Point[] { new Point(Width - 20, (Height / 2) - 2), new Point(Width - 9, (Height / 2) - 2), new Point(Width - 15, (Height / 2) + 4) }); //e.Graphics.FillPolygon(b, new Point[] { new Point(Width - 15, (Height / 2) - 5), new Point(Width - 21, (Height / 2) + 2), new Point(Width - 9, (Height / 2) + 2) }); } int _check = 0; if (this.ShowCheckBox) { _check = 15; using (Pen p = new Pen(borderColor)) { Rectangle boxRect = new Rectangle(3, Height / 2 - 6, 12, 12); e.Graphics.DrawRectangle(p, boxRect); } if (Checked) { Color fillColor = MetroPaint.GetStyleColor(Style); using (SolidBrush b = new SolidBrush(fillColor)) { Rectangle boxRect = new Rectangle(5, Height / 2 - 4, 9, 9); e.Graphics.FillRectangle(b, boxRect); } } else { foreColor = MetroPaint.ForeColor.ComboBox.Disabled(Theme); } } Rectangle textRect = new Rectangle(2 + _check, 2, Width - 20, Height - 4); TextRenderer.DrawText(e.Graphics, Text, MetroFonts.DateTime(metroDateTimeSize, metroDateTimeWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (displayFocusRectangle && isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } }
public GraphicsPath Create(int x, int y, int width, int height, int radius, RectangleCorners corners) { int xw = x + width; int yh = y + height; int xwr = xw - radius; int yhr = yh - radius; int xr = x + radius; int yr = y + radius; int r2 = radius * 2; int xwr2 = xw - r2; int yhr2 = yh - r2; GraphicsPath p = new GraphicsPath(); p.StartFigure(); //Top Left Corner if ((RectangleCorners.TopLeft & corners) == RectangleCorners.TopLeft) { p.AddArc(x, y, r2, r2, 180, 90); } else { p.AddLine(x, yr, x, y); p.AddLine(x, y, xr, y); } //Top Edge p.AddLine(xr, y, xwr, y); //Top Right Corner if ((RectangleCorners.TopRight & corners) == RectangleCorners.TopRight) { p.AddArc(xwr2, y, r2, r2, 270, 90); } else { p.AddLine(xwr, y, xw, y); p.AddLine(xw, y, xw, yr); } //Right Edge p.AddLine(xw, yr, xw, yhr); //Bottom Right Corner if ((RectangleCorners.BottomRight & corners) == RectangleCorners.BottomRight) { p.AddArc(xwr2, yhr2, r2, r2, 0, 90); } else { p.AddLine(xw, yhr, xw, yh); p.AddLine(xw, yh, xwr, yh); } //Bottom Edge p.AddLine(xwr, yh, xr, yh); //Bottom Left Corner if ((RectangleCorners.BottomLeft & corners) == RectangleCorners.BottomLeft) { p.AddArc(x, yhr2, r2, r2, 90, 90); } else { p.AddLine(xr, yh, x, yh); p.AddLine(x, yh, x, yhr); } //Left Edge p.AddLine(x, yhr, x, yr); p.CloseFigure(); return(p); }
public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null) { using (var path = new GraphicsPath()) { var bb = new BoundingBoxBuilder(); var position = Point.Zero; foreach (var op in ops) { var mt = op as MoveTo; if (mt != null) { var p = mt.Point; position = p; bb.Add(p); continue; } var lt = op as LineTo; if (lt != null) { var p = lt.Point; path.AddLine(Conversions.GetPointF(position), Conversions.GetPointF(p)); position = p; bb.Add(p); continue; } var at = op as ArcTo; if (at != null) { var p = at.Point; path.AddLine(Conversions.GetPointF(position), Conversions.GetPointF(p)); position = p; bb.Add(p); continue; } var ct = op as CurveTo; if (ct != null) { var p = ct.Point; var c1 = ct.Control1; var c2 = ct.Control2; path.AddBezier(Conversions.GetPointF(position), Conversions.GetPointF(c1), Conversions.GetPointF(c2), Conversions.GetPointF(p)); position = p; bb.Add(p); bb.Add(c1); bb.Add(c2); continue; } var cp = op as ClosePath; if (cp != null) { path.CloseFigure(); continue; } throw new NotSupportedException("Path Op " + op); } var frame = bb.BoundingBox; if (brush != null) { graphics.FillPath(brush.GetBrush(frame), path); } if (pen != null) { graphics.DrawPath(pen.GetPen(), path); } } }
/// <summary> /// This gets called to instruct the element to draw itself in the appropriate spot of the graphics object /// </summary> /// <param name="g">The graphics object to draw to</param> /// <param name="printing">boolean, true if printing to the actual paper/document, false if drawing as a control</param> public override void Draw(Graphics g, bool printing) { GraphicsPath gp = new GraphicsPath(); Point[] pts; Matrix m = new Matrix(Size.Width / 100F, 0F, 0F, Size.Height / 100F, Location.X, Location.Y); m.RotateAt(_rotation, new PointF(50F, 50F), MatrixOrder.Prepend); Pen mypen = new Pen(_color, 2F); SolidBrush fillBrush = new SolidBrush(_color); mypen.LineJoin = LineJoin.Round; mypen.StartCap = LineCap.Round; mypen.EndCap = LineCap.Round; //All north arrows are defined as a graphics path in 100x100 size which is then scaled to fit the rectangle of the element switch (_northArrowStyle) { case (NorthArrowStyle.BlackArrow): gp.AddLine(50, 5, 5, 50); gp.AddLine(5, 50, 30, 50); gp.AddLine(30, 50, 30, 95); gp.AddLine(30, 95, 70, 95); gp.AddLine(70, 95, 70, 50); gp.AddLine(70, 50, 95, 50); gp.CloseFigure(); gp.Transform(m); g.DrawPath(mypen, gp); g.FillPath(fillBrush, gp); //N gp = new GraphicsPath(); gp.AddLine(40, 80, 40, 45); gp.StartFigure(); gp.AddLine(40, 45, 60, 80); gp.StartFigure(); gp.AddLine(60, 80, 60, 45); gp.StartFigure(); mypen.Color = Color.White; mypen.Width = Size.Width / 20; gp.Transform(m); g.DrawPath(mypen, gp); break; case (NorthArrowStyle.Default): //draw the outline DrawOutline(gp); gp.CloseFigure(); //Draw the N gp.AddLine(45, 57, 45, 43); gp.StartFigure(); gp.AddLine(45, 43, 55, 57); gp.StartFigure(); gp.AddLine(55, 57, 55, 43); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); //Draw the top arrow gp = new GraphicsPath(); gp.AddLine(50, 5, 60, 40); gp.AddBezier(60, 40, 55, 35, 45, 35, 40, 40); gp.CloseFigure(); gp.Transform(m); g.DrawPath(mypen, gp); g.FillPath(fillBrush, gp); break; case (NorthArrowStyle.CenterStar): //Outline DrawOutline(gp); gp.AddBezier(40F, 40F, 45F, 35F, 55F, 35F, 60f, 40F); gp.AddLine(60, 40, 50, 5); gp.CloseFigure(); //N gp.AddLine(47, 33, 47, 20); gp.StartFigure(); gp.AddLine(47, 20, 53, 33); gp.StartFigure(); gp.AddLine(53, 33, 53, 20); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); //Draw the center circle gp = new GraphicsPath(); gp.AddLine(30, 30, 40, 50); gp.AddLine(40, 50, 30, 70); gp.AddLine(30, 70, 50, 60); gp.AddLine(50, 60, 70, 70); gp.AddLine(70, 70, 60, 50); gp.AddLine(60, 50, 70, 30); gp.AddLine(70, 30, 50, 40); gp.CloseFigure(); gp.Transform(m); g.DrawPath(mypen, gp); g.FillPath(fillBrush, gp); break; case (NorthArrowStyle.TriangleN): pts = new Point[3]; pts[0] = new Point(50, 5); pts[1] = new Point(5, 95); pts[2] = new Point(95, 95); gp.AddLines(pts); gp.CloseFigure(); gp.AddLine(40, 80, 40, 45); gp.StartFigure(); gp.AddLine(40, 45, 60, 80); gp.StartFigure(); gp.AddLine(60, 80, 60, 45); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); break; case (NorthArrowStyle.TriangleHat): pts = new Point[3]; pts[0] = new Point(50, 5); pts[1] = new Point(5, 60); pts[2] = new Point(95, 60); gp.AddLines(pts); gp.CloseFigure(); gp.AddLine(5, 95, 5, 65); gp.StartFigure(); gp.AddLine(5, 65, 95, 95); gp.StartFigure(); gp.AddLine(95, 95, 95, 65); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); break; case (NorthArrowStyle.ArrowN): pts = new Point[3]; pts[0] = new Point(5, 25); pts[1] = new Point(50, 5); pts[2] = new Point(95, 25); gp.AddLines(pts); gp.CloseFigure(); gp.AddLine(50, 25, 50, 95); gp.StartFigure(); gp.AddLine(5, 80, 5, 45); gp.StartFigure(); gp.AddLine(5, 45, 95, 80); gp.StartFigure(); gp.AddLine(95, 80, 95, 45); gp.StartFigure(); gp.Transform(m); g.DrawPath(mypen, gp); break; } gp.Dispose(); }
public override void ReEvaluateComputeValue(ref ReEvaluateArgs args) { var myspec = this.spec; this.fillColor = myspec.FillColor; this.strokeColor = myspec.StrokeColor; this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args); if (this.IsPathValid) { return; } ClearCachePath(); if (segments == null) { this.myCachedPath = null; } else if (_vxs != null) { //this is flatten vxs? GraphicsPath gpath = this.myCachedPath = new GraphicsPath(); int cmdCount = _vxs.Count; double lastMoveX = 0, lastMoveY = 0, curX = 0, curY = 0; for (int i = 0; i < cmdCount; ++i) { var cmd = _vxs.GetVertex(i, out double x, out double y); switch (cmd) { case VertexCmd.MoveTo: gpath.StartFigure(); curX = lastMoveX = x; curY = lastMoveY = y; break; case VertexCmd.LineTo: gpath.AddLine((float)curX, (float)curY, (float)x, (float)y); curX = x; curY = y; break; //case PixelFarm.Agg.VertexCmd.P2c: // segments.Add(new SvgPathSegLineTo((float)x, (float)y)); // break; //case PixelFarm.Agg.VertexCmd.P3c: // segments.Add(new SvgPathSegLineTo((float)x, (float)y)); // break; //case PixelFarm.Agg.VertexCmd.EndFigure: // break; //case PixelFarm.Agg.VertexCmd.CloseAndEndFigure: //case PixelFarm.Agg.VertexCmd.NoMore: case VertexCmd.Close: gpath.CloseFigure(); break; case VertexCmd.NoMore: i = cmdCount; //force stop break; default: throw new NotSupportedException(); } } } else { List <SvgPathSeg> segs = this.segments; int segcount = segs.Count; GraphicsPath gpath = this.myCachedPath = new GraphicsPath(); float lastMoveX = 0; float lastMoveY = 0; PointF lastPoint = new PointF(); PointF p2 = new PointF(); //curve control point PointF p3 = new PointF(); //curve control point PointF intm_c3_c = new PointF(); for (int i = 0; i < segcount; ++i) { SvgPathSeg seg = segs[i]; switch (seg.Command) { case SvgPathCommand.ZClosePath: { gpath.CloseFigure(); } break; case SvgPathCommand.MoveTo: { var moveTo = (SvgPathSegMoveTo)seg; PointF moveToPoint; moveTo.GetAbsolutePoints(ref lastPoint, out moveToPoint); lastPoint = moveToPoint; gpath.StartFigure(); lastMoveX = lastPoint.X; lastMoveY = lastPoint.Y; } break; case SvgPathCommand.LineTo: { var lineTo = (SvgPathSegLineTo)seg; PointF lineToPoint; lineTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; case SvgPathCommand.HorizontalLineTo: { var hlintTo = (SvgPathSegLineToHorizontal)seg; PointF lineToPoint; hlintTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; case SvgPathCommand.VerticalLineTo: { var vlineTo = (SvgPathSegLineToVertical)seg; PointF lineToPoint; vlineTo.GetAbsolutePoints(ref lastPoint, out lineToPoint); gpath.AddLine(lastPoint, lineToPoint); lastPoint = lineToPoint; } break; //--------------------------------------------------------------------------- //curve modes...... case SvgPathCommand.CurveTo: { //cubic curve to (2 control points) var cubicCurve = (SvgPathSegCurveToCubic)seg; PointF p; cubicCurve.GetAbsolutePoints(ref lastPoint, out p2, out p3, out p); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; case SvgPathCommand.QuadraticBezierCurve: { //quadratic curve (1 control point) //auto calculate for c1,c2 var quadCurve = (SvgPathSegCurveToQuadratic)seg; PointF p; quadCurve.GetAbsolutePoints(ref lastPoint, out intm_c3_c, out p); SvgCurveHelper.Curve3GetControlPoints(lastPoint, intm_c3_c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; //------------------------------------------------------------------------------------ case SvgPathCommand.SmoothCurveTo: { //smooth cubic curve to var smthC4 = (SvgPathSegCurveToCubicSmooth)seg; PointF c2, p; smthC4.GetAbsolutePoints(ref lastPoint, out c2, out p); //connect with prev segment if (i > 0) { //------------------ //calculate p1 from prev segment //------------------ var prevSeg = segments[i - 1]; //check if prev is curve switch (prevSeg.Command) { case SvgPathCommand.Arc: case SvgPathCommand.CurveTo: case SvgPathCommand.SmoothCurveTo: case SvgPathCommand.QuadraticBezierCurve: case SvgPathCommand.TSmoothQuadraticBezierCurveTo: //make mirror point p2 = SvgCurveHelper.CreateMirrorPoint(p3, lastPoint); p3 = c2; gpath.AddBezierCurve(lastPoint, p2, p3, p); break; default: continue; } } lastPoint = p; } break; case SvgPathCommand.TSmoothQuadraticBezierCurveTo: { //curve 3 var smtC3 = (SvgPathSegCurveToQuadraticSmooth)seg; PointF p; smtC3.GetAbsolutePoints(ref lastPoint, out p); if (i > 0) { //------------------ //calculate p1 from prev segment //------------------ var prevSeg = segments[i - 1]; //check if prev is curve switch (prevSeg.Command) { case SvgPathCommand.Arc: case SvgPathCommand.CurveTo: case SvgPathCommand.SmoothCurveTo: { PointF c = SvgCurveHelper.CreateMirrorPoint(p3, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; } break; case SvgPathCommand.TSmoothQuadraticBezierCurveTo: { //make mirror point PointF c = SvgCurveHelper.CreateMirrorPoint(intm_c3_c, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; intm_c3_c = c; } break; case SvgPathCommand.QuadraticBezierCurve: { PointF c = SvgCurveHelper.CreateMirrorPoint(intm_c3_c, lastPoint); SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3); gpath.AddBezierCurve(lastPoint, p2, p3, p); lastPoint = p; intm_c3_c = c; } break; default: continue; } } lastPoint = p; } break; case SvgPathCommand.Arc: { var arcTo = (SvgPathSegArc)seg; PointF p; arcTo.GetAbsolutePoints(ref lastPoint, out p); if (lastPoint.IsEq(p)) { return; } if (arcTo.R1 == 0 && arcTo.R2 == 0) { gpath.AddLine(lastPoint, p); lastPoint = p; return; } PointF[] bz4Points; SvgCurveHelper.MakeBezierCurveFromArc( ref lastPoint, ref p, arcTo.R1, arcTo.R2, arcTo.Angle, arcTo.LargeArgFlag, arcTo.SweepFlag, out bz4Points); int j = bz4Points.Length; int nn = 0; while (nn < j) { gpath.AddBezierCurve( bz4Points[nn], bz4Points[nn + 1], bz4Points[nn + 2], bz4Points[nn + 3]); nn += 4; //step 4 points } //set control points p3 = bz4Points[nn - 2]; p2 = bz4Points[nn - 3]; lastPoint = p; //--------------------------------------------- } break; default: throw new NotSupportedException(); } } } ValidatePath(); }
void bg_DoWork(object sender, DoWorkEventArgs e) { MapInfo info = (MapInfo)e.Argument; if (!info.Area.IsEmpty) { string bigImage = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "GMap at zoom " + info.Zoom + " - " + info.Type + "-" + DateTime.Now.Ticks + ".jpg"; e.Result = bigImage; // current area GPoint topLeftPx = info.Type.Projection.FromLatLngToPixel(info.Area.LocationTopLeft, info.Zoom); GPoint rightButtomPx = info.Type.Projection.FromLatLngToPixel(info.Area.Bottom, info.Area.Right, info.Zoom); GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y); GMap.NET.GSize maxOfTiles = info.Type.Projection.GetTileMatrixMaxXY(info.Zoom); int padding = info.MakeWorldFile || info.MakeKmz ? 0 : 22; { using (Bitmap bmpDestination = new Bitmap((int)(pxDelta.X + padding * 2), (int)(pxDelta.Y + padding * 2))) { using (Graphics gfx = Graphics.FromImage(bmpDestination)) { gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx.SmoothingMode = SmoothingMode.HighQuality; int i = 0; // get tiles & combine into one lock (tileArea) { foreach (var p in tileArea) { if (bg.CancellationPending) { e.Cancel = true; return; } int pc = (int)(((double)++i / tileArea.Count) * 100); bg.ReportProgress(pc, p); foreach (var tp in info.Type.Overlays) { Exception ex; GMapImage tile; // tile number inversion(BottomLeft -> TopLeft) for pergo maps if (tp.InvertedAxisY) { tile = GMaps.Instance.GetImageFrom(tp, new GPoint(p.X, maxOfTiles.Height - p.Y), info.Zoom, out ex) as GMapImage; } else // ok { tile = GMaps.Instance.GetImageFrom(tp, p, info.Zoom, out ex) as GMapImage; } if (tile != null) { using (tile) { long x = p.X * info.Type.Projection.TileSize.Width - topLeftPx.X + padding; long y = p.Y * info.Type.Projection.TileSize.Width - topLeftPx.Y + padding; { gfx.DrawImage(tile.Img, x, y, info.Type.Projection.TileSize.Width, info.Type.Projection.TileSize.Height); } } } } } } // draw routes { foreach (GMapRoute r in Main.routes.Routes) { if (r.IsVisible) { using (GraphicsPath rp = new GraphicsPath()) { for (int j = 0; j < r.Points.Count; j++) { var pr = r.Points[j]; GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom); px.Offset(padding, padding); px.Offset(-topLeftPx.X, -topLeftPx.Y); GPoint p2 = px; if (j == 0) { rp.AddLine(p2.X, p2.Y, p2.X, p2.Y); } else { System.Drawing.PointF p = rp.GetLastPoint(); rp.AddLine(p.X, p.Y, p2.X, p2.Y); } } if (rp.PointCount > 0) { gfx.DrawPath(r.Stroke, rp); } } } } } // draw polygons { foreach (GMapPolygon r in Main.polygons.Polygons) { if (r.IsVisible) { using (GraphicsPath rp = new GraphicsPath()) { for (int j = 0; j < r.Points.Count; j++) { var pr = r.Points[j]; GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom); px.Offset(padding, padding); px.Offset(-topLeftPx.X, -topLeftPx.Y); GPoint p2 = px; if (j == 0) { rp.AddLine(p2.X, p2.Y, p2.X, p2.Y); } else { System.Drawing.PointF p = rp.GetLastPoint(); rp.AddLine(p.X, p.Y, p2.X, p2.Y); } } if (rp.PointCount > 0) { rp.CloseFigure(); gfx.FillPath(r.Fill, rp); gfx.DrawPath(r.Stroke, rp); } } } } } // draw markers { foreach (GMapMarker r in Main.objects.Markers) { if (r.IsVisible) { var pr = r.Position; GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom); px.Offset(padding, padding); px.Offset(-topLeftPx.X, -topLeftPx.Y); px.Offset(r.Offset.X, r.Offset.Y); gfx.ResetTransform(); gfx.TranslateTransform(-r.LocalPosition.X, -r.LocalPosition.Y); gfx.TranslateTransform((int)px.X, (int)px.Y); r.OnRender(gfx); } } // tooltips above foreach (GMapMarker m in Main.objects.Markers) { if (m.IsVisible && m.ToolTip != null && m.IsVisible) { if (!string.IsNullOrEmpty(m.ToolTipText)) { var pr = m.Position; GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom); px.Offset(padding, padding); px.Offset(-topLeftPx.X, -topLeftPx.Y); px.Offset(m.Offset.X, m.Offset.Y); gfx.ResetTransform(); gfx.TranslateTransform(-m.LocalPosition.X, -m.LocalPosition.Y); gfx.TranslateTransform((int)px.X, (int)px.Y); m.ToolTip.OnRender(gfx); } } } gfx.ResetTransform(); } // draw info if (!info.MakeWorldFile) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); { rect.Location = new System.Drawing.Point(padding, padding); rect.Size = new System.Drawing.Size((int)pxDelta.X, (int)pxDelta.Y); } using (Font f = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold)) { // draw bounds & coordinates using (Pen p = new Pen(Brushes.DimGray, 3)) { p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; gfx.DrawRectangle(p, rect); string topleft = info.Area.LocationTopLeft.ToString(); SizeF s = gfx.MeasureString(topleft, f); gfx.DrawString(topleft, f, p.Brush, rect.X + s.Height / 2, rect.Y + s.Height / 2); string rightBottom = new PointLatLng(info.Area.Bottom, info.Area.Right).ToString(); SizeF s2 = gfx.MeasureString(rightBottom, f); gfx.DrawString(rightBottom, f, p.Brush, rect.Right - s2.Width - s2.Height / 2, rect.Bottom - s2.Height - s2.Height / 2); } // draw scale using (Pen p = new Pen(Brushes.Blue, 1)) { double rez = info.Type.Projection.GetGroundResolution(info.Zoom, info.Area.Bottom); int px100 = (int)(100.0 / rez); // 100 meters int px1000 = (int)(1000.0 / rez); // 1km gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px1000, 10); gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px100, 10); string leftBottom = "scale: 100m | 1Km"; SizeF s = gfx.MeasureString(leftBottom, f); gfx.DrawString(leftBottom, f, p.Brush, rect.X + 10, rect.Bottom - s.Height - 20); } } } } bmpDestination.Save(bigImage, ImageFormat.Jpeg); } } //The worldfile for the original image is: //0.000067897543 // the horizontal size of a pixel in coordinate units (longitude degrees in this case); //0.0000000 //0.0000000 //-0.0000554613012 // the comparable vertical pixel size in latitude degrees, negative because latitude decreases as you go from top to bottom in the image. //-111.743323868834 // longitude of the pixel in the upper-left-hand corner. //35.1254392635083 // latitude of the pixel in the upper-left-hand corner. // generate world file if (info.MakeWorldFile) { string wf = bigImage + "w"; using (StreamWriter world = File.CreateText(wf)) { world.WriteLine("{0:0.000000000000}", (info.Area.WidthLng / pxDelta.X)); world.WriteLine("0.0000000"); world.WriteLine("0.0000000"); world.WriteLine("{0:0.000000000000}", (-info.Area.HeightLat / pxDelta.Y)); world.WriteLine("{0:0.000000000000}", info.Area.Left); world.WriteLine("{0:0.000000000000}", info.Area.Top); world.Close(); } } if (info.MakeKmz) { var kmzFile = Path.GetDirectoryName(bigImage) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(bigImage) + ".kmz"; e.Result = kmzFile; using (ZipStorer zip = ZipStorer.Create(kmzFile, "GMap.NET")) { zip.AddFile(ZipStorer.Compression.Store, bigImage, "files/map.jpg", "map"); using (var readme = new MemoryStream( Encoding.UTF8.GetBytes( string.Format(CultureInfo.InvariantCulture, @"<?xml version=""1.0"" encoding=""UTF-8""?> <kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom""> <GroundOverlay> <name>{8}</name> <LookAt> <longitude>{6}</longitude> <latitude>{7}</latitude> <altitude>0</altitude> <heading>0</heading> <tilt>0</tilt> <range>69327.55500845652</range> </LookAt> <color>91ffffff</color> <Icon> <href>files/map.jpg</href> </Icon> <gx:LatLonQuad> <coordinates> {0},{1},0 {2},{3},0 {4},{5},0 {6},{7},0 </coordinates> </gx:LatLonQuad> </GroundOverlay> </kml>", info.Area.Left, info.Area.Bottom, info.Area.Right, info.Area.Bottom, info.Area.Right, info.Area.Top, info.Area.Left, info.Area.Top, kmzFile)))) { zip.AddStream(ZipStorer.Compression.Store, "doc.kml", readme, DateTime.Now, "kml"); zip.Close(); } } } } }
private List <SpeedPercentZone> PaintSpeedPart(Graphics g, Rectangle speedRect, int shadowOffset) { float wideOffset = Math.Max(0, speedRect.Width / 20); Rectangle rect = new Rectangle(speedRect.Left, speedRect.Top + (int)wideOffset, speedRect.Width - shadowOffset, speedRect.Height - shadowOffset - 2 * (int)wideOffset); Point mousePos = this.PointToClient(Cursor.Position); float r = rect.Width / 2f; List <SpeedPercentZone> zones = new List <SpeedPercentZone>(); #region BG GraphicsPath bgPath = new GraphicsPath(); bgPath.AddArc(new RectangleF(rect.X, rect.Y, rect.Width, rect.Width), 180, 180); bgPath.AddArc(new RectangleF(rect.X, rect.Bottom - rect.Width, rect.Width, rect.Width), 0, 180); bgPath.CloseFigure(); using (var b = new LinearGradientBrush(rect, ScaleColor(230), ScaleColor(100), LinearGradientMode.Vertical)) using (var p = new Pen(Color.FromArgb(Enabled ? 128 : 64, ForeColor))) { PaintIcon(g, bgPath, b, p, shadowOffset); } #endregion if (!this.Enabled) { return(zones); } #region CreateZones var hcolor = Color.FromArgb(128, SystemColors.Highlight); GraphicsPath p100 = new GraphicsPath(); p100.AddArc(new RectangleF(rect.X - wideOffset, rect.Y - wideOffset, rect.Width + wideOffset * 2, rect.Width + wideOffset), 180, 180); p100.CloseFigure(); var pz100 = new SpeedPercentZone(p100, SpeedMaximum, ScaleColor(200)); zones.Add(pz100); GraphicsPath p1 = new GraphicsPath(); p1.AddArc(new RectangleF(rect.X - wideOffset, rect.Bottom - rect.Width + wideOffset, rect.Width + wideOffset * 2, rect.Width + wideOffset), 0, 180); p1.CloseFigure(); var pz1 = new SpeedPercentZone(p1, SpeedMinimum, ScaleColor(100)); zones.Add(pz1); var irect = new Rectangle(rect.X, rect.Y + rect.Width / 2, rect.Width, rect.Height - rect.Width); float zh = (irect.Height) / 99f; SpeedPercentZone currentZone = SpeedValue <= SpeedMinimum ? pz1 : SpeedValue >= SpeedMaximum ? pz100 : null; for (int i = 1; i < 99; i++) { var p = new GraphicsPath(); p.AddRectangle(new RectangleF(irect.X - wideOffset, irect.Y + i * zh, irect.Width + wideOffset * 2, Math.Max(5, zh))); var pzI = new SpeedPercentZone(p, SpeedPercent2Value(100 - i), ScaleColor(100 - i)); zones.Add(pzI); if (SpeedValue == pzI.Speed) { currentZone = pzI; } } #endregion var oldtransform = g.Transform; #region draw Hot zone SpeedPercentZone info = null; foreach (var z in zones) { if (z.HitTest(mousePos)) { using (var b = new SolidBrush(hcolor)) using (var p = new Pen(Color.FromArgb(64, ForeColor))) PaintIcon(g, z.Path, b, p, 0); info = z; break; } } #endregion #region Draw Current if (currentZone != null) { if (info == null) { info = currentZone; } int nalpha = this.Enabled ? 128 : 64; int halpha = 255; using (var hb = new SolidBrush(Color.FromArgb(halpha, SystemColors.Highlight))) using (var p = new Pen(Color.FromArgb(Enabled ? 128 : 64, ForeColor))) { PaintIcon(g, currentZone.Path, hb, p, shadowOffset); } } if (info != null && rect.Contains(mousePos)) { var txt = string.Format("F {0}", info.Speed); var s = g.MeasureString(txt, this.Font); g.DrawString(txt, Font, Brushes.Black, new PointF(rect.Right + 5, rect.Bottom - s.Height)); } #endregion g.Transform = oldtransform; return(zones); }
/// <summary> /// Generates the rounded rectangle. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="rectangle">The rectangle.</param> /// <param name="radius">The radius.</param> /// <param name="filter">The filter.</param> /// <returns>GraphicsPath.</returns> private static GraphicsPath GenerateRoundedRectangle( this Graphics graphics, RectangleF rectangle, float radius, RectangleEdgeFilter filter) { float diameter; GraphicsPath path = new GraphicsPath(); if (radius <= 0.0F || filter == RectangleEdgeFilter.None) { path.AddRectangle(rectangle); path.CloseFigure(); return(path); } else { if (radius >= (System.Math.Min(rectangle.Width, rectangle.Height)) / 2.0) { return(graphics.GenerateCapsule(rectangle)); } diameter = radius * 2.0F; SizeF sizeF = new SizeF(diameter, diameter); RectangleF arc = new RectangleF(rectangle.Location, sizeF); if ((RectangleEdgeFilter.TopLeft & filter) == RectangleEdgeFilter.TopLeft) { path.AddArc(arc, 180, 90); } else { path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y); path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y); } arc.X = rectangle.Right - diameter; if ((RectangleEdgeFilter.TopRight & filter) == RectangleEdgeFilter.TopRight) { path.AddArc(arc, 270, 90); } else { path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y); path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X + arc.Width, arc.Y); } arc.Y = rectangle.Bottom - diameter; if ((RectangleEdgeFilter.BottomRight & filter) == RectangleEdgeFilter.BottomRight) { path.AddArc(arc, 0, 90); } else { path.AddLine(arc.X + arc.Width, arc.Y, arc.X + arc.Width, arc.Y + arc.Height); path.AddLine(arc.X, arc.Y + arc.Height, arc.X + arc.Width, arc.Y + arc.Height); } arc.X = rectangle.Left; if ((RectangleEdgeFilter.BottomLeft & filter) == RectangleEdgeFilter.BottomLeft) { path.AddArc(arc, 90, 90); } else { path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X, arc.Y + arc.Height); path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y); } path.CloseFigure(); } return(path); }
/// <summary> /// /// </summary> /// <param name="Rect"></param> /// <returns></returns> private GraphicsPath CreateTabPath(Rectangle Rect) { GraphicsPath path = new GraphicsPath(); switch (Alignment) { case TabAlignment.Top: Rect.X++; Rect.Width -= 2; path.AddLine( Rect.X, Rect.Bottom, Rect.X, Rect.Y + _Radius / 2); path.AddArc( Rect.X, Rect.Y, _Radius, _Radius, 180F, 90F); path.AddArc( Rect.Right - _Radius, Rect.Y, _Radius, _Radius, 270F, 90F); path.AddLine( Rect.Right, Rect.Y + _Radius / 2, Rect.Right, Rect.Bottom); break; case TabAlignment.Bottom: Rect.X++; Rect.Width -= 2; path.AddLine( Rect.X, Rect.Y, Rect.X, Rect.Bottom - _Radius / 2); path.AddArc( Rect.X, Rect.Bottom - _Radius, _Radius, _Radius, 180, -90); path.AddArc( Rect.Right - _Radius, Rect.Bottom - _Radius, _Radius, _Radius, 90, -90); path.AddLine( Rect.Right, Rect.Bottom - _Radius / 2, Rect.Right, Rect.Y); break; case TabAlignment.Left: Rect.Y++; Rect.Height -= 2; path.AddLine( Rect.Right, Rect.Y, Rect.X + _Radius / 2, Rect.Y); path.AddArc( Rect.X, Rect.Y, _Radius, _Radius, 270F, -90F); path.AddArc( Rect.X, Rect.Bottom - _Radius, _Radius, _Radius, 180F, -90F); path.AddLine( Rect.X + _Radius / 2, Rect.Bottom, Rect.Right, Rect.Bottom); break; case TabAlignment.Right: Rect.Y++; Rect.Height -= 2; path.AddLine( Rect.X, Rect.Y, Rect.Right - _Radius / 2, Rect.Y); path.AddArc( Rect.Right - _Radius, Rect.Y, _Radius, _Radius, 270F, 90F); path.AddArc( Rect.Right - _Radius, Rect.Bottom - _Radius, _Radius, _Radius, 0F, 90F); path.AddLine( Rect.Right - _Radius / 2, Rect.Bottom, Rect.X, Rect.Bottom); break; } path.CloseFigure(); return(path); }
protected override void OnPaint(PaintEventArgs e) { #region Transparency if (transparency && Parent != null) { Bitmap behind = new Bitmap(Parent.Width, Parent.Height); foreach (Control c in Parent.Controls) { if (c.Bounds.IntersectsWith(this.Bounds) & c != this) { c.DrawToBitmap(behind, c.Bounds); } } e.Graphics.DrawImage(behind, -Left, -Top); behind.Dispose(); } #endregion #region DrawCircle float angle = (value * 360.0f / maxValue); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; RectangleF outerRect = new RectangleF(0, 0, outerRadius * 2, outerRadius * 2); RectangleF innerRect = new RectangleF(outerRadius - innerRadius, outerRadius - innerRadius, innerRadius * 2, innerRadius * 2); using (GraphicsPath progPath = new GraphicsPath()) { progPath.AddArc(outerRect, angle - 90, -angle); if (allowText) { progPath.AddArc(innerRect, -90, angle); } else { progPath.AddLine(new Point(outerRadius, 0), new Point(outerRadius, outerRadius)); } progPath.CloseFigure(); e.Graphics.FillPath(brush, progPath); } #endregion #region DrawString if (!allowText) { return; } string text = "%" + (value * 100.0 / maxValue).ToString("0"); Size textSize; float ratio = 1.0f; if (automaticFontCalculation) { string fullPercText = "%100"; Size temp = TextRenderer.MeasureText(fullPercText, this.Font); float properWidth = innerRadius * 1.2f; ratio = properWidth / temp.Width; } Font font = new Font(Font.Name, Font.Height * ratio); textSize = TextRenderer.MeasureText(text, font); float x = (2 * outerRadius - textSize.Width) / 2f; float y = (2 * outerRadius - textSize.Height) / 2f; using (SolidBrush textBrush = new SolidBrush(ForeColor)) e.Graphics.DrawString(text, font, textBrush, x + 1, y); #endregion }
private Region CreateRoundedRectangleRegion(int radius, Rectangle rectangle) { using (GraphicsPath Path = new GraphicsPath()) { int Radius2 = (radius * 2); Path.FillMode = FillMode.Winding; Path.StartFigure(); Path.AddArc(rectangle.X, rectangle.Y, Radius2, Radius2, 180, 90); Path.AddLine(rectangle.X + radius, rectangle.Y, rectangle.Right - radius, rectangle.Y); Path.AddArc(rectangle.Right - Radius2 - 1, rectangle.Y, Radius2, Radius2, 270, 90); Path.AddLine(rectangle.Right, rectangle.Y + radius, rectangle.Right, rectangle.Bottom - radius); Path.AddArc(rectangle.Right - Radius2 - 1, rectangle.Bottom - Radius2 - 1, Radius2, Radius2, 0, 90); Path.AddLine(rectangle.Right - radius, rectangle.Bottom, rectangle.X + radius, rectangle.Bottom); Path.AddArc(rectangle.X, rectangle.Bottom - Radius2 - 1, Radius2, Radius2, 90, 90); Path.AddLine(rectangle.X, rectangle.Bottom - radius, rectangle.X, rectangle.Y + radius); Path.CloseFigure(); return new Region(Path); } }
// REAL MAGIC HERE! y- B- private void DrawData(Graphics g, float Xunit, float Yunit,int xstart ) { PeptideMW PMW = new PeptideMW(PeptideSequence); float[] Bs = PMW.GetPepFragmentBValues(); float[] Ys = PMW.GetPepFragmentYValues(); bool bPhos = PMW.IsPhosphorylation(); int Count = SpectrumData.Count; int i = 0; for (i = 0; i < Count; i++) { float mz = ((MZintensitiy )SpectrumData[i]).mz ; float intensity = ((MZintensitiy )SpectrumData[i]).intensity ; float x = (mz - xstart)*Xunit + NETAREALEFTMARGIN ; float y; if (bZoomOut) { if (intensity * 100 / MaxIntensitiy > DisplayMaxY) { y = NETAREATOPMARGIN ; } else { y = HEIGHT - NETAREABOTTOMMARGIN - intensity * 100 * Yunit / MaxIntensitiy; } } else y = HEIGHT - NETAREABOTTOMMARGIN - intensity * 100 * Yunit / MaxIntensitiy; Pen dataPen = new Pen (Brushes.Black ,1); Pen BLinePen = new Pen(Brushes.Blue, 2); Pen YLinePen = new Pen(Brushes.Red, 2); Pen ALinePen = new Pen (Brushes.Green ,2); Pen MLinePen = new Pen(Brushes.Gray , 2); Font Numberfont = new Font("Arial", 9, FontStyle.Regular); if (y < HEIGHT - NETAREABOTTOMMARGIN -20 && bShowLabel ) { string strAnn = GetAnnotation(SpectrumData,i, Bs, Ys,PrecursorMZ,int.Parse (ChargeState ),bPhos ); if (strAnn.StartsWith("(b")) { g.DrawLine(BLinePen, x, y, x, (float)HEIGHT - NETAREABOTTOMMARGIN); g.DrawString(strAnn, Numberfont, Brushes.Blue , new PointF(x, y)); } else if (strAnn.StartsWith("(y")) { g.DrawLine(YLinePen, x, y, x, (float)HEIGHT - NETAREABOTTOMMARGIN); g.DrawString(strAnn, Numberfont, Brushes.Red, new PointF(x, y)); } else if (strAnn.StartsWith("(a")) { g.DrawLine(ALinePen, x, y, x, (float)HEIGHT - NETAREABOTTOMMARGIN); g.DrawString(strAnn, Numberfont, Brushes.Green, new PointF(x, y)); } else if (strAnn.StartsWith("(M") && y < HEIGHT - NETAREABOTTOMMARGIN -100) { g.DrawLine(MLinePen, x, y, x, (float)HEIGHT - NETAREABOTTOMMARGIN); g.DrawString(strAnn, Numberfont, Brushes.Gray , new PointF(x, y)); } else { g.DrawLine(dataPen, x, y, x, (float)HEIGHT - NETAREABOTTOMMARGIN); } //g.DrawString(strAnn, Numberfont, Brushes.Red, new PointF(x, y)); } else g.DrawLine(dataPen, x, y, x, (float)HEIGHT - NETAREABOTTOMMARGIN); if (intensity == MaxIntensitiy) { //peak value point GraphicsPath p = new GraphicsPath(); p.AddLine(x, (float)HEIGHT - NETAREABOTTOMMARGIN, x + XAxisScaleLength, (float)HEIGHT - NETAREABOTTOMMARGIN + XAxisScaleLength); p.AddLine(x + XAxisScaleLength, (float)HEIGHT - NETAREABOTTOMMARGIN + XAxisScaleLength, x - XAxisScaleLength, (float)HEIGHT - NETAREABOTTOMMARGIN + XAxisScaleLength); p.CloseFigure(); g.FillPath(Brushes.Red, p); g.DrawString(mz.ToString(), Numberfont, Brushes.Red, x + XAxisScaleLength, (float)HEIGHT - NETAREABOTTOMMARGIN); } } }
private GraphicsPath DrawArrow(int x, int y, bool flip) { GraphicsPath GP = new GraphicsPath(); int W = 5; int H = 9; if (flip) { GP.AddLine(x, y + 1, x, y + H + 1); GP.AddLine(x, y + H, x + W - 1, y + W); } else { GP.AddLine(x + W, y, x + W, y + H); GP.AddLine(x + W, y + H, x + 1, y + W); } GP.CloseFigure(); return GP; }
public static GraphicsPath MakeRoundedRect( RectangleF rect, float xradius, float yradius, bool round_ul, bool round_ur, bool round_lr, bool round_ll) { // Make a GraphicsPath to draw the rectangle. PointF point1, point2; GraphicsPath path = new GraphicsPath(); // Upper left corner. if (round_ul) { RectangleF corner = new RectangleF( rect.X, rect.Y, 2 * xradius, 2 * yradius); path.AddArc(corner, 180, 90); point1 = new PointF(rect.X + xradius, rect.Y); } else { point1 = new PointF(rect.X, rect.Y); } // Top side. if (round_ur) { point2 = new PointF(rect.Right - xradius, rect.Y); } else { point2 = new PointF(rect.Right, rect.Y); } path.AddLine(point1, point2); // Upper right corner. if (round_ur) { RectangleF corner = new RectangleF( rect.Right - 2 * xradius, rect.Y, 2 * xradius, 2 * yradius); path.AddArc(corner, 270, 90); point1 = new PointF(rect.Right, rect.Y + yradius); } else { point1 = new PointF(rect.Right, rect.Y); } // Right side. if (round_lr) { point2 = new PointF(rect.Right, rect.Bottom - yradius); } else { point2 = new PointF(rect.Right, rect.Bottom); } path.AddLine(point1, point2); // Lower right corner. if (round_lr) { RectangleF corner = new RectangleF( rect.Right - 2 * xradius, rect.Bottom - 2 * yradius, 2 * xradius, 2 * yradius); path.AddArc(corner, 0, 90); point1 = new PointF(rect.Right - xradius, rect.Bottom); } else { point1 = new PointF(rect.Right, rect.Bottom); } // Bottom side. if (round_ll) { point2 = new PointF(rect.X + xradius, rect.Bottom); } else { point2 = new PointF(rect.X, rect.Bottom); } path.AddLine(point1, point2); // Lower left corner. if (round_ll) { RectangleF corner = new RectangleF( rect.X, rect.Bottom - 2 * yradius, 2 * xradius, 2 * yradius); path.AddArc(corner, 90, 90); point1 = new PointF(rect.X, rect.Bottom - yradius); } else { point1 = new PointF(rect.X, rect.Bottom); } // Left side. if (round_ul) { point2 = new PointF(rect.X, rect.Y + yradius); } else { point2 = new PointF(rect.X, rect.Y); } path.AddLine(point1, point2); // Join with the start point. path.CloseFigure(); return(path); }
private void Draw3DBorder(Graphics g, float offset, Brush color, bool fill, float r, float percent) { int pen_width = 2; float x = this.ClientRectangle.Left + (pen_width / 2) + offset; float y = this.ClientRectangle.Top + (pen_width / 2) + offset; float w = (this.ClientRectangle.Width - (pen_width / 2 + 2 + offset * 2)) * percent; float h = this.ClientRectangle.Height - (pen_width / 2 + 2 + offset * 2); Pen pen = new Pen(color, (float)pen_width); GraphicsPath path = new GraphicsPath(); if (w < 2 * r) { w = 2 * r; } path.AddLine(x + r, y, x + (w - r * 2), y); path.AddArc(x + w - r * 2, y, r * 2, r * 2, 270, 90); path.AddLine(x + w, y + r, x + w, y + h - r * 2); path.AddArc(x + w - r * 2, y + h - r * 2, r * 2, r * 2, 0, 90); path.AddLine(x + w - r * 2, y + h, x + r, y + h); path.AddArc(x, y + h - r * 2, r * 2, r * 2, 90, 90); path.AddLine(x, y + h - r * 2, x, y + r); path.AddArc(x, y, r * 2, r * 2, 180, 90); path.CloseFigure(); g.SmoothingMode = SmoothingMode.AntiAlias; if (fill) { g.FillPath(color, path); } else { g.DrawPath(pen, path); } }
protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; g.Clear(Color.White); using (var dataPointPath = new GraphicsPath()) using (var gridPen = new Pen(Color.FromArgb(20, Color.Black))) using (var dashPen = new Pen(MainColor) { DashStyle = DashStyle.Dash }) using (var borderPen = new Pen(MainColor)) using (var fillBrush = new SolidBrush(Color.FromArgb(35, MainColor))) using (var textBrush = new SolidBrush(MainColor)) { if (DataPoints.Count > 1) { var infoRect = new Rectangle(); var highlightRect = new RectangleF(); var infoString = string.Empty; dataPointPath.AddLine(Width + 10, Height + 10, Width + 10, Height + 10); var offset = 0; for (var i = DataPoints.Count - 1; i >= 1; i--) { if (DataPoints[i].Index % LineDensity == 0) g.DrawLine(gridPen, Width - offset, 0, Width - offset, Height); var scaledY = GetScaledPoint(DataPoints[i].Value); dataPointPath.AddLine(Width - offset, scaledY, Width - offset - PointDensity, GetScaledPoint(DataPoints[i - 1].Value)); if (HighlightPoint && new Rectangle(Width - offset - (PointDensity / 2), 0, PointDensity, Height).Contains(MouseLocation)) { g.DrawLine(gridPen, 0, scaledY, Width, scaledY); highlightRect = new RectangleF(Width - offset - 3, scaledY - 3, 6, 6); infoString = DataPoints[i].Value.ToString(CultureInfo.InvariantCulture); var infoStringSize = TextRenderer.MeasureText(infoString, Font); infoRect = new Rectangle { Height = infoStringSize.Height + 2, Width = infoStringSize.Width + 5 }; if (offset < infoStringSize.Width + 10) infoRect.X = Width - offset - infoStringSize.Width - 10; else infoRect.X = Width - offset + 5; if (scaledY > Height - infoStringSize.Height - 5) infoRect.Y = (int)scaledY - infoStringSize.Height - 5; else infoRect.Y = (int)scaledY + 5; } offset += PointDensity; } dataPointPath.AddLine(-10, Height + 10, -10, Height + 10); dataPointPath.CloseFigure(); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(fillBrush, dataPointPath); g.DrawPath(borderPen, dataPointPath); g.SmoothingMode = SmoothingMode.None; if (ShowAverage) { var average = GetScaledPoint(GetAverage()); g.DrawLine(dashPen, 0, average, Width, average); g.FillRectangle(fillBrush, 0, average, Width, Height - average); } if (HighlightPoint) { g.SmoothingMode = SmoothingMode.AntiAlias; g.FillEllipse(Brushes.White, highlightRect); g.DrawEllipse(borderPen, highlightRect); g.SmoothingMode = SmoothingMode.None; g.FillRectangle(Brushes.White, infoRect); g.DrawRectangle(borderPen, infoRect); g.DrawString(infoString, HighlightFont, textBrush, infoRect.X + 4, infoRect.Y + 1); } } g.DrawRectangle(borderPen, new Rectangle(0, 0, Width - 1, Height - 1)); } }
public void CreateRegion() { // создание контура GraphicsPath path; Region tmp_region; Rectangle base_rect = new Rectangle(delta, delta, Picture.Width - 2 * delta, Picture.Height - 2 * delta); // создание региона на основе контура Region new_region = new Region(base_rect); if (RType_Top != RegionType.none) { path = new GraphicsPath(); path.StartFigure(); path.AddEllipse(delta + (Picture.Width - 2 * delta) / 2, delta / 2, delta, delta); path.CloseFigure(); tmp_region = new Region(path); if (RType_Top == RegionType.Union) { new_region.Union(tmp_region); } else if (RType_Top == RegionType.Exclude) { new_region.Exclude(tmp_region); } } if (RType_Bottom != RegionType.none) { path = new GraphicsPath(); path.StartFigure(); path.AddEllipse(delta + (Picture.Width - 2 * delta) / 2, Picture.Height - 3 * delta / 2, delta, delta); path.CloseFigure(); tmp_region = new Region(path); if (RType_Bottom == RegionType.Union) { new_region.Union(tmp_region); } else if (RType_Bottom == RegionType.Exclude) { new_region.Exclude(tmp_region); } } if (RType_Left != RegionType.none) { path = new GraphicsPath(); path.StartFigure(); path.AddEllipse(delta / 2, delta + (Picture.Height - 2 * delta) / 2, delta, delta); path.CloseFigure(); tmp_region = new Region(path); if (RType_Left == RegionType.Union) { new_region.Union(tmp_region); } else if (RType_Left == RegionType.Exclude) { new_region.Exclude(tmp_region); } } if (RType_Right != RegionType.none) { path = new GraphicsPath(); path.StartFigure(); path.AddEllipse(Picture.Width - 3 * delta / 2, delta + (Picture.Height - 2 * delta) / 2, delta, delta); path.CloseFigure(); tmp_region = new Region(path); if (RType_Right == RegionType.Union) { new_region.Union(tmp_region); } else if (RType_Right == RegionType.Exclude) { new_region.Exclude(tmp_region); } } this.Region = new_region; }
private void OnDrawTabPage(Graphics g, FATabStripItem currentItem) { bool isFirstTab = Items.IndexOf(currentItem) == 0; Font currentFont = Font; if (currentItem == SelectedItem) { currentFont = new Font(Font, FontStyle.Bold); } SizeF textSize = g.MeasureString(currentItem.Title, SystemFonts.DefaultFont, new SizeF(200, 10), sf); textSize.Width += 20; RectangleF buttonRect = currentItem.StripRect; GraphicsPath path = new GraphicsPath(); LinearGradientBrush brush; int mtop = 3; #region Draw Not Right-To-Left Tab if (RightToLeft == RightToLeft.No) { //if (currentItem == SelectedItem || isFirstTab) //{ // path.AddLine(buttonRect.Left - 10, buttonRect.Bottom - 1, // buttonRect.Left + (buttonRect.Height/2) - 4, mtop + 4); //} //else //{ // path.AddLine(buttonRect.Left, buttonRect.Bottom - 1, buttonRect.Left, // buttonRect.Bottom - (buttonRect.Height/2) - 2); // path.AddLine(buttonRect.Left, buttonRect.Bottom - (buttonRect.Height/2) - 3, // buttonRect.Left + (buttonRect.Height/2) - 4, mtop + 3); //} //path.AddLine(buttonRect.Left + (buttonRect.Height/2) + 2, mtop, buttonRect.Right - 3, mtop); //path.AddLine(buttonRect.Right, mtop + 2, buttonRect.Right, buttonRect.Bottom - 1); //path.AddLine(buttonRect.Right - 4, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - 1); path.AddRectangle(buttonRect); path.CloseFigure(); if (currentItem == SelectedItem) { brush = new LinearGradientBrush(buttonRect, SystemColors.ActiveCaption, SystemColors.ActiveCaption, LinearGradientMode.Vertical); } else { brush = new LinearGradientBrush(buttonRect, SystemColors.InactiveCaption, SystemColors.InactiveCaption, LinearGradientMode.Vertical); } g.FillPath(brush, path); g.DrawPath(new Pen(brush, 1), path); //if (currentItem == SelectedItem) //{ // g.DrawLine(new Pen(brush), buttonRect.Left, buttonRect.Height + 2, // buttonRect.Left + buttonRect.Width, buttonRect.Height + 2); //} double dpiscale = g.DpiX / 96.0; var tmargin = 15 * (float)(dpiscale + 0.3) / 2; PointF textLoc = new PointF(buttonRect.Left + tmargin, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2); RectangleF textRect = buttonRect; textRect.Location = textLoc; //textRect.Width = buttonRect.Width - (textRect.Left - buttonRect.Left) - 4; //textRect.Height = textSize.Height + currentFont.Size/2; if (currentItem == SelectedItem) { //textRect.Y -= 2; g.DrawString(currentItem.Title, SystemFonts.DefaultFont, new SolidBrush(SystemColors.ActiveCaptionText), textRect, sf); } else { g.DrawString(currentItem.Title, SystemFonts.DefaultFont, new SolidBrush(SystemColors.ActiveCaptionText), textRect, sf); } } #endregion #region Draw Right-To-Left Tab if (RightToLeft == RightToLeft.Yes) { if (currentItem == SelectedItem || isFirstTab) { path.AddLine(buttonRect.Right + 10, buttonRect.Bottom - 1, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 4); } else { path.AddLine(buttonRect.Right, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 2); path.AddLine(buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 3); } path.AddLine(buttonRect.Right - (buttonRect.Height / 2) - 2, mtop, buttonRect.Left + 3, mtop); path.AddLine(buttonRect.Left, mtop + 2, buttonRect.Left, buttonRect.Bottom - 1); path.AddLine(buttonRect.Left + 4, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - 1); path.CloseFigure(); if (currentItem == SelectedItem) { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Window, LinearGradientMode.Vertical); } else { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical); } g.FillPath(brush, path); g.DrawPath(SystemPens.ControlDark, path); if (currentItem == SelectedItem) { g.DrawLine(new Pen(brush), buttonRect.Right + 9, buttonRect.Height + 2, buttonRect.Right - buttonRect.Width + 1, buttonRect.Height + 2); } PointF textLoc = new PointF(buttonRect.Left + 2, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2); RectangleF textRect = buttonRect; textRect.Location = textLoc; textRect.Width = buttonRect.Width - (textRect.Left - buttonRect.Left) - 10; textRect.Height = textSize.Height + currentFont.Size / 2; if (currentItem == SelectedItem) { textRect.Y -= 1; g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } else { g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } //g.FillRectangle(Brushes.Red, textRect); } #endregion currentItem.IsDrawn = true; }
public static void RoundedRect(Graphics aGraph, Rectangle aRect, int aR, Pen aPen, Brush aBrush) { // First, build path: GraphicsPath lPath = new GraphicsPath(); lPath.StartFigure(); lPath.AddArc(aRect.Left, aRect.Top, aR, aR, 180, 90); lPath.AddArc(aRect.Left + aRect.Width - aR, aRect.Top, aR, aR, 270, 90); lPath.AddArc(aRect.Left + aRect.Width - aR, aRect.Top + aRect.Height - aR, aR, aR, 0, 90); lPath.AddArc(aRect.Left + 0, aRect.Top + aRect.Height - aR, aR, aR, 90, 90); lPath.CloseFigure(); if (aBrush != null) aGraph.FillPath(aBrush, lPath); if (aPen != null) aGraph.DrawPath(aPen, lPath); }