private void Render(IGraphics ig) { string s = cbWhat.Text; if (string.IsNullOrEmpty(s)) { } else if (s == "Clipping") { Pen pn = new Pen(Color.LightGray, 5.6f); Pen pn2 = new Pen(Color.Yellow, 1.2f); ig.Clear(Color.Black); GraphicsContainer cnt = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; ig.SetClip(new Rectangle(35, 35, 120, 120)); ig.DrawRectangle(pn, 5, 5, 45, 70); ig.DrawRectangle(pn, 15, 25, 90, 120); ig.DrawRectangle(pn, 50, 30, 100, 170); ig.DrawRectangle(pn, 5, 80, 180, 30); ig.DrawRectangle(pn, 75, 10, 40, 160); ig.EndContainer(cnt); ig.DrawRectangle(pn2, 5, 5, 45, 70); ig.DrawRectangle(pn2, 15, 25, 90, 120); ig.DrawRectangle(pn2, 50, 30, 100, 170); ig.DrawRectangle(pn2, 5, 80, 180, 30); ig.DrawRectangle(pn2, 75, 10, 40, 160); } else if (s == "Transforms") { ig.Clear(Color.Black); ig.RotateTransform(15); ig.DrawRectangle(new Pen(Color.Red, 2.7f), 260, 80, 50, 40); ig.ResetTransform(); ig.DrawRectangle(new Pen(Color.Red, 2.7f), 260, 80, 50, 40); ig.TranslateTransform(15, -5); GraphicsContainer cnt = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; ig.RotateTransform(5); ig.FillEllipse(new SolidBrush(Color.Orange), 100, 100, 80, 40); ig.DrawRectangle(new Pen(Color.Orange, 2), 60, 80, 40, 40); GraphicsContainer cnt2 = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.None; ig.RotateTransform(5); ig.ScaleTransform(1.1f, 1.2f); ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130, 180, 80, 40); ig.DrawRectangle(new Pen(Color.YellowGreen, 2.7f), 62, 80, 40, 40); GraphicsContainer cnt3 = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; Matrix mm = new Matrix(); mm.Shear(0.3f, 0f); ig.Transform = mm; ig.FillEllipse(new SolidBrush(Color.Green), 180, 120, 80, 40); ig.DrawRectangle(new Pen(Color.Green, 2), 62, 84, 40, 40); ig.EndContainer(cnt3); ig.EndContainer(cnt2); ig.FillEllipse(new SolidBrush(Color.Blue), 120, 150, 80, 40); ig.DrawRectangle(new Pen(Color.Blue, 2), 64, 80, 40, 40); ig.EndContainer(cnt); ig.FillEllipse(new SolidBrush(Color.Indigo), 80, 210, 80, 40); ig.DrawRectangle(new Pen(Color.Indigo, 2), 66, 80, 40, 40); ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40); ig.ResetTransform(); ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40); } else if (s == "Lines") { ig.SmoothingMode = SmoothingMode.AntiAlias; Pen ow = new Pen(Color.Purple, 12.6f); ow.EndCap = LineCap.Round; ow.StartCap = LineCap.Round; ow.MiterLimit = 6f; ow.LineJoin = LineJoin.Miter; ig.SmoothingMode = SmoothingMode.None; Pen tp = new Pen(Color.Red, 2.7f); tp.DashStyle = DashStyle.DashDot; ig.DrawLine(tp, 70, 20, 190, 20); tp.DashStyle = DashStyle.Dash; ig.DrawLine(tp, 70, 30, 190, 30); tp.DashStyle = DashStyle.Custom; tp.DashPattern = new float[] { 1, 8, 2, 2 }; ig.DrawLine(tp, 70, 40, 190, 40); ig.SmoothingMode = SmoothingMode.AntiAlias; PointF[] pts = new PointF[4]; pts[0] = new PointF(20, 50); pts[1] = new PointF(30, 90); pts[2] = new PointF(65, 60); pts[3] = new PointF(50, 40); ig.DrawLines(ow, pts); Point[] polly = new Point[] { new Point(200, 40), new Point(220, 140), new Point(240, 100), new Point(290, 70), new Point(230, 10) }; ig.DrawPolygon(tp, polly); //arrows Pen arr = new Pen(Color.DarkGoldenrod, 5.7f); { arr.Width = 2; arr.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; const float arrowWidth = 11.0f; // TUNE: const float arrowHeight = 14f; // TUNE: var arrowOutline = new System.Drawing.Drawing2D.GraphicsPath(); arrowOutline.AddLines(new PointF[] { new PointF(-(arrowWidth / 2), -arrowHeight), new PointF(0, 0), new PointF((arrowWidth / 2), -arrowHeight), new PointF(-(arrowWidth / 2), -arrowHeight) }); var generalizationArrow = new System.Drawing.Drawing2D.CustomLineCap(null, arrowOutline); generalizationArrow.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round); generalizationArrow.BaseInset = arrowHeight; arr.CustomEndCap = generalizationArrow; ig.DrawLine(arr, 0, 120, 100, 200); } arr.Width = 5; AdjustableArrowCap aac = new AdjustableArrowCap(5, 3, false); arr.EndCap = LineCap.Custom; arr.CustomEndCap = aac; arr.StartCap = LineCap.ArrowAnchor; ig.DrawLine(arr, 50, 120, 150, 200); arr.Width = 7f; arr.EndCap = LineCap.RoundAnchor; arr.StartCap = LineCap.SquareAnchor; ig.DrawLine(arr, 100, 120, 200, 200); arr.Width = 9; arr.EndCap = LineCap.DiamondAnchor; arr.StartCap = LineCap.ArrowAnchor; ig.DrawLine(arr, 150, 120, 250, 200); Point[] al = new Point[] { new Point(200, 100), new Point(300, 200), new Point(300, 150) }; arr.Width = 9; arr.EndCap = LineCap.DiamondAnchor; arr.StartCap = LineCap.DiamondAnchor; ig.DrawLines(arr, al); } else if (s == "Curves") { PointF[] bezzie = new PointF[] { new PointF(20, 150), new PointF(110, 190), new PointF(120, 200), new PointF(50, 220), new PointF(60, 200), new PointF(140, 180), new PointF(100, 160), new PointF(180, 260), new PointF(200, 210), new PointF(190, 210) }; Pen bpn = new Pen(Color.MediumSeaGreen, 2.3f); bpn.DashStyle = DashStyle.Custom; bpn.DashPattern = new float[] { 6, 1, 5, 2, 4, 3, 3, 4, 2, 5, 6, 1 }; ig.DrawBeziers(bpn, bezzie); PointF[] curvy = new PointF[] { new PointF(130, 40), new PointF(70, 70), new PointF(50, 20), new PointF(120, 120), new PointF(150, 80), new PointF(80, 150), new PointF(80, 110) }; ig.DrawCurve(new Pen(Color.Blue, 5.7f), curvy); ig.DrawCurve(new Pen(Color.Red, 2.7f), curvy, 2, 3); ig.DrawCurve(new Pen(Color.Yellow, 1.7f), curvy, 1f); Point[] ccurvy = new Point[] { new Point(280, 30), new Point(260, 60), new Point(200, 20), new Point(290, 120), new Point(290, 80), new Point(230, 150), new Point(150, 50) }; ig.DrawClosedCurve(new Pen(Color.Green, 3.7f), ccurvy, 1f, FillMode.Alternate); ig.DrawClosedCurve(new Pen(Color.Purple, 1.7f), ccurvy, 0f, FillMode.Alternate); Point[] fcc = new Point[] { new Point(160, 350), new Point(190, 370), new Point(130, 390), new Point(190, 400), new Point(195, 410), new Point(100, 430), new Point(160, 450) }; ig.FillClosedCurve(new SolidBrush(Color.Red), fcc, FillMode.Winding, 1f); ig.FillClosedCurve(new SolidBrush(Color.Aquamarine), fcc, FillMode.Alternate, .2f); } else if (s == "Transparency") { Point[] fillpoly = new Point[] { new Point(20, 130), new Point(60, 90), new Point(30, 20), new Point(80, 20), new Point(15, 90), new Point(100, 50), new Point(0, 50) }; Color col = Color.FromArgb(96, 255, 0, 0); ig.FillEllipse(new SolidBrush(Color.Ivory), 60, 140, 60, 30); ig.FillPolygon(new SolidBrush(Color.Ivory), fillpoly, FillMode.Winding); ig.TranslateTransform(10, 10); ig.FillEllipse(new SolidBrush(col), 60, 140, 60, 30); ig.FillPolygon(new SolidBrush(col), fillpoly, FillMode.Alternate); ig.ResetTransform(); ig.FillPie(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), 10, 200, 200, 80, 315, 90); ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 128, 0)), 10, 200, 200, 80, 250, -90); ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 0, 128)), 15, 205, 190, 70, 180, 270); ig.FillPie(new SolidBrush(Color.FromArgb(100, 200, 60, 60)), 20, 210, 180, 60, 45, -270); } else if (s == "Fills") { LinearGradientBrush gbr1 = new LinearGradientBrush(new Point(0, 0), new Point(30, 20), Color.Blue, Color.Plum); ColorBlend blend = new ColorBlend(3); blend.Colors = new Color[] { Color.Red, Color.Yellow, Color.MediumSlateBlue }; blend.Positions = new float[] { 0, .3f, 1f }; gbr1.InterpolationColors = blend; Point[] sp = new Point[] { new Point(145, 145), new Point(305, 250), new Point(220, 250), new Point(180, 250) }; ig.FillPolygon(gbr1, sp); LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue); gbr2.WrapMode = WrapMode.TileFlipXY; Point[] sp2 = new Point[] { new Point(25, 205), new Point(75, 150), new Point(110, 110), new Point(40, 80) }; ig.FillPolygon(gbr2, sp2); ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalBrick, Color.Khaki, Color.Peru), 000, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Vertical, Color.Bisque, Color.Peru), 020, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.DarkVertical, Color.Tan, Color.Peru), 040, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalCross, Color.Chocolate, Color.Peru), 060, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.WideDownwardDiagonal, Color.BurlyWood, Color.Peru), 080, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.LargeConfetti, Color.Wheat, Color.Peru), 100, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.ZigZag, Color.SaddleBrown, Color.Peru), 120, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.HorizontalBrick, Color.Linen, Color.Peru), 140, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.LightHorizontal, Color.Maroon, Color.Peru), 160, 5, 20, 20); ig.FillRectangle(gbr1, 200, 5, 20, 20); ig.FillRectangle(gbr2, 220, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent05, Color.CornflowerBlue, Color.LemonChiffon), 000, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent10, Color.CornflowerBlue, Color.LemonChiffon), 020, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent20, Color.CornflowerBlue, Color.LemonChiffon), 040, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent25, Color.CornflowerBlue, Color.LemonChiffon), 060, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent30, Color.CornflowerBlue, Color.LemonChiffon), 080, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent40, Color.CornflowerBlue, Color.LemonChiffon), 100, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent50, Color.CornflowerBlue, Color.LemonChiffon), 120, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent60, Color.CornflowerBlue, Color.LemonChiffon), 140, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent70, Color.CornflowerBlue, Color.LemonChiffon), 160, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent75, Color.CornflowerBlue, Color.LemonChiffon), 180, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent80, Color.CornflowerBlue, Color.LemonChiffon), 200, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent90, Color.CornflowerBlue, Color.LemonChiffon), 220, 30, 20, 20); } else if (s == "Arcs/Pies") { //GDI does not seem to draw arcs correctly except when the ellipse is a circle. //These arcs demonstrate the problem. SVGGraphics calculates arcs correctly. ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 5 * 3, 120, 110 * 3, 110, 0, 240); ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 10 * 3, 125, 100 * 3, 100, 0, 210); ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 15 * 3, 130, 90 * 3, 90, 0, 180); ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 20 * 3, 135, 80 * 3, 80, 0, 150); ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 25 * 3, 140, 70 * 3, 70, 0, 120); ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 30 * 3, 145, 60 * 3, 60, 0, 90); ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 35 * 3, 150, 50 * 3, 50, 0, 60); ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 40 * 3, 155, 40 * 3, 40, 0, 270); ig.DrawPie(new Pen(Color.Pink, 2.7f), 110, 50, 100, 100, 315, 90); ig.DrawPie(new Pen(Color.Purple, 2.7f), 110, 50, 100, 100, 250, -90); ig.DrawPie(new Pen(Color.DarkRed, 2.7f), 115, 55, 90, 90, 180, 270); ig.DrawPie(new Pen(Color.Red, 2.7f), 120, 60, 80, 80, 45, -270); } else if (s == "Text") { Font fnt1 = new Font("Helvetica", 12, FontStyle.Italic | FontStyle.Bold); Font fnt2 = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold); Font fnt3 = new Font("", 40, FontStyle.Underline); Rectangle rc1 = new Rectangle(30, 30, 220, 20); StringFormat fmt1 = new StringFormat(); fmt1.Alignment = StringAlignment.Near; ig.DrawRectangle(new Pen(Color.Blue), rc1); ig.DrawString("Text...1", fnt1, new SolidBrush(Color.DarkGreen), rc1, fmt1); Rectangle rc2 = new Rectangle(0, 0, 120, 20); StringFormat fmt2 = new StringFormat(); fmt2.Alignment = StringAlignment.Center; ig.TranslateTransform(30, 160); ig.RotateTransform(90); ig.DrawRectangle(new Pen(Color.Blue), rc2); ig.DrawString("Text...2", fnt2, new SolidBrush(Color.DarkGreen), rc2, fmt2); ig.ResetTransform(); Rectangle rc3 = new Rectangle(30, 90, 300, 30); StringFormat fmt3 = new StringFormat(); fmt3.Alignment = StringAlignment.Far; ig.DrawRectangle(new Pen(Color.Blue), rc3); ig.DrawString("Text...3", fnt3, new SolidBrush(Color.DarkGreen), rc3, fmt3); //measurestring const string mme = "MeasureString Is Impossible To Emulate"; SizeF siz = ig.MeasureString(mme, fnt1); ig.DrawRectangle(new Pen(Color.Red), 20, 200, siz.Width, siz.Height); siz = ig.MeasureString(mme, fnt1, 150); ig.DrawRectangle(new Pen(Color.Orange), 20, 230, siz.Width, siz.Height); siz = ig.MeasureString(mme, fnt1, new SizeF(150, 150), new StringFormat(StringFormatFlags.DirectionVertical)); ig.DrawRectangle(new Pen(Color.Yellow), 20, 200, siz.Width, siz.Height); } else if (s == "Rect-aligned Text") { ig.Clear(Color.White); ig.ScaleTransform( (float)panel1.ClientSize.Width / RectAlignedTextTest.CanvasSize, (float)panel1.ClientSize.Height / RectAlignedTextTest.CanvasSize); RectAlignedTextTest.DrawTest(ig); } else if (s == "Images") { Icon ike = new Icon(GetType(), "App.ico"); ig.DrawIcon(ike, 10, 10); //ig.DrawIcon(ike, new Rectangle(270, 400, 30, 40)); Bitmap bmp = new Bitmap(GetType(), "test.bmp"); ig.DrawImage(bmp, 100f, 150f); GraphicsContainer cnt = ig.BeginContainer(); ig.RotateTransform(5); ig.DrawImage(bmp, 160f, 50f, 120f, 70f); ig.EndContainer(cnt); //ig.DrawImageUnscaled(bmp, 270, 450, 20, 20); } else if (s == "Path") { /* The following example GraphicsPath code comes from the MSDN docs on the GraphicsPathIterator class * https://msdn.microsoft.com/en-us/library/79k451ts.aspx * */ // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up primitives to add to myPath. Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, an ellipse, and 2 markers. myPath.AddLines(myPoints); myPath.SetMarkers(); myPath.AddRectangle(myRect); myPath.SetMarkers(); myPath.AddEllipse(220, 220, 100, 100); ig.DrawPath(new Pen(Color.Black, 1.7f), myPath); LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue); gbr2.WrapMode = WrapMode.TileFlipXY; ig.FillPath(gbr2, myPath); GraphicsPath myPath2 = new GraphicsPath(); myPath2.AddLine(100, 100, 130, 120); myPath2.AddEllipse(120, 120, 120, 140); myPath2.AddBezier(130, 160, 170, 160, 150, 130, 200, 110); ig.DrawPath(new Pen(Color.Blue, 1.7f), myPath2); } else if (s == "Path 2 (Slow)") { SolidBrush mySolidBrush = new SolidBrush(Color.Aqua); GraphicsPath myGraphicsPath = new GraphicsPath(); Point[] myPointArray = { new Point(15, 20), new Point(20, 40), new Point(50, 30) }; FontFamily myFontFamily = new FontFamily("Times New Roman"); PointF myPointF = new PointF(50, 20); StringFormat myStringFormat = new StringFormat(); myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180); myGraphicsPath.AddCurve(myPointArray); myGraphicsPath.AddString("a string in a path filled", myFontFamily, 0, 24, myPointF, myStringFormat); myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110); ig.FillPath(mySolidBrush, myGraphicsPath); ig.DrawPath(new Pen(Color.Green, 1.7f), myGraphicsPath); } else { throw new NotImplementedException(); } }
private static void RenderLines(IGraphics ig) { ig.SmoothingMode = SmoothingMode.AntiAlias; var ow = new Pen(Color.Purple, 12.6f) { EndCap = LineCap.Round, StartCap = LineCap.Round, MiterLimit = 6f, LineJoin = LineJoin.Miter }; ig.SmoothingMode = SmoothingMode.None; var tp = new Pen(Color.Red, 2.7f) { DashStyle = DashStyle.DashDot }; ig.DrawLine(tp, 70, 20, 190, 20); tp.DashStyle = DashStyle.Dash; ig.DrawLine(tp, 70, 30, 190, 30); tp.DashStyle = DashStyle.Custom; tp.DashPattern = new float[] { 1, 8, 2, 2 }; ig.DrawLine(tp, 70, 40, 190, 40); ig.SmoothingMode = SmoothingMode.AntiAlias; var pts = new PointF[4]; pts[0] = new PointF(20, 50); pts[1] = new PointF(30, 90); pts[2] = new PointF(65, 60); pts[3] = new PointF(50, 40); ig.DrawLines(ow, pts); var polly = new Point[] { new Point(200, 40), new Point(220, 140), new Point(240, 100), new Point(290, 70), new Point(230, 10) }; ig.DrawPolygon(tp, polly); //arrows var arr = new Pen(Color.DarkGoldenrod, 5.7f); { arr.Width = 2; arr.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; const float arrowWidth = 11.0f; // TUNE: const float arrowHeight = 14f; // TUNE: var arrowOutline = new System.Drawing.Drawing2D.GraphicsPath(); arrowOutline.AddLines(new PointF[] { new PointF(-(arrowWidth / 2), -arrowHeight), new PointF(0, 0), new PointF(arrowWidth / 2, -arrowHeight), new PointF(-(arrowWidth / 2), -arrowHeight) }); var generalizationArrow = new System.Drawing.Drawing2D.CustomLineCap(null, arrowOutline); generalizationArrow.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round); generalizationArrow.BaseInset = arrowHeight; arr.CustomEndCap = generalizationArrow; ig.DrawLine(arr, 0, 120, 100, 200); } arr.Width = 5; var aac = new AdjustableArrowCap(5, 3, false); arr.EndCap = LineCap.Custom; arr.CustomEndCap = aac; arr.StartCap = LineCap.ArrowAnchor; ig.DrawLine(arr, 50, 120, 150, 200); arr.Width = 7f; arr.EndCap = LineCap.RoundAnchor; arr.StartCap = LineCap.SquareAnchor; ig.DrawLine(arr, 100, 120, 200, 200); arr.Width = 9; arr.EndCap = LineCap.DiamondAnchor; arr.StartCap = LineCap.ArrowAnchor; ig.DrawLine(arr, 150, 120, 250, 200); var al = new Point[] { new Point(200, 100), new Point(300, 200), new Point(300, 150) }; arr.Width = 9; arr.EndCap = LineCap.DiamondAnchor; arr.StartCap = LineCap.DiamondAnchor; ig.DrawLines(arr, al); }
//------------------------------------------------------------------------ public override void DrawExpression(CContextDessinObjetGraphique ctx, CRepresentationExpressionGraphique expressionGraphique) { C2iExpressionObjet expObjet = expressionGraphique.Formule as C2iExpressionObjet; if (expObjet == null) { return; } Rectangle rct = expressionGraphique.RectangleAbsolu; Rectangle[] rcts = new Rectangle[] { new Rectangle(rct.Left, rct.Top, rct.Width, rct.Height / 2), new Rectangle(rct.Left, rct.Top + rct.Height / 2, rct.Width, rct.Height / 2) }; //Dessin des deux paramètres for (int n = 0; n < 2; n++) { CRepresentationExpressionGraphique exp = new CRepresentationExpressionGraphique(); exp.Position = new Point(rcts[n].Left, rcts[n].Top); exp.Size = new Size(rcts[n].Width, rcts[n].Height); if (expObjet.Parametres.Count > n) { exp.Formule = expObjet.Parametres2i[n]; } CDessineurExpressionGraphique dessineur = CDessineurExpressionGraphique.GetDessineur(exp); if (dessineur != null) { dessineur.DrawExpression(ctx, exp); } } StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; Font ft = new Font(FontFamily.GenericSansSerif, 8); AdjustableArrowCap cap = new AdjustableArrowCap(4, 4, true); C2iExpressionGraphique rep = expressionGraphique.RepresentationRacine; if (rep != null) { Pen pen = new Pen(Brushes.DarkGreen, 1); pen.DashStyle = DashStyle.DashDotDot; pen.EndCap = LineCap.Custom; pen.CustomEndCap = cap; foreach (string strLien in expressionGraphique.IdElementsUtilises) { CRepresentationExpressionGraphique exp = rep.GetFormule(strLien); if (exp != null) { DrawLien(ctx, pen, ft, exp, expressionGraphique, ""); } } pen.Dispose(); } CRepresentationExpressionGraphique next = expressionGraphique.Next; if (next != null) { Pen pen = new Pen(Brushes.Black, 3); pen.CustomEndCap = cap; DrawLien(ctx, pen, ft, expressionGraphique, next, ""); pen.Dispose(); } cap.Dispose(); ft.Dispose(); }
//vẽ đường cong public void DrawCurve(Graphics g, Point p1, Point p2, string s, Font f, Brush br, int penwidth, bool directed) { g.SmoothingMode = SmoothingMode.AntiAlias; Pen pen = new Pen(br); pen.Width = penwidth; //tính toán chiều dài và độ di chuyển tọa độ một khoảng x, y float a = Math.Abs(p2.X - p1.X); float b = Math.Abs(p2.Y - p1.Y); float c = (float)Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2)); float x = a * (radius / c); float y = b * (radius / c); PointF _p1 = new PointF(); PointF _p2 = new PointF(); PointF _p3 = new PointF(); //Xét các trường hợp để có độ cong chuẩn xác nhất if (p1.Y == p2.Y) { if (p1.X < p2.X) { _p2.X = p1.X + a / 2; _p2.Y = p1.Y - r; } else { _p2.X = p2.X + a / 2; _p2.Y = p2.Y + r; } } else if (p1.X == p2.X) { if (p1.Y < p2.Y) { _p2.X = p1.X + r; _p2.Y = p1.Y + b / 2; } else { _p2.X = p2.X - r; _p2.Y = p2.Y + b / 2; } } else { float m, n; if (a >= b) { float h = (b * c) / (2 * a); float l = (b * b) / (2 * a); m = ((h - r) * b) / (2 * h); n = a / 2 + (l * r) / h; } else { float h = (a * c) / (2 * b); float l = (a * a) / (2 * b); n = ((h - r) * a) / (2 * h); m = b / 2 + (l * r) / h; } if (p1.X < p2.X && p1.Y < p2.Y) { _p2.X = p1.X + n; _p2.Y = p1.Y + m; } else if (p1.X < p2.X) { _p2.X = p1.X + n; _p2.Y = p1.Y - m; } else if (p1.X > p2.X && p1.Y > p2.Y) { _p2.X = p1.X - n; _p2.Y = p1.Y - m; } else { _p2.X = p1.X - n; _p2.Y = p1.Y + m; } } //Xét các trường hợp để di chuyển tọa độ chuẩn xác nhất if (p1.X <= p2.X && p1.Y <= p2.Y) { _p1.X = p1.X + x; _p1.Y = p1.Y + y; _p3.X = p2.X - x; _p3.Y = p2.Y - y; } else if (p1.X <= p2.X) { _p1.X = p1.X + x; _p1.Y = p1.Y - y; _p3.X = p2.X - x; _p3.Y = p2.Y + y; } else if (p1.X >= p2.X && p1.Y >= p2.Y) { _p1.X = p1.X - x; _p1.Y = p1.Y - y; _p3.X = p2.X + x; _p3.Y = p2.Y + y; } else { _p1.X = p1.X - x; _p1.Y = p1.Y + y; _p3.X = p2.X + x; _p3.Y = p2.Y - y; } //nếu đồ thị có hướng cần vẽ thêm mũi tên if (directed) { AdjustableArrowCap cap = new AdjustableArrowCap(3.5F, 3.5F); pen.CustomEndCap = cap; } g.DrawCurve(pen, new PointF[] { _p1, _p2, _p3 }); //vẽ trọng số cho cạnh StringFormat myformat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; float textwidth = g.MeasureString(s, f).Width; float textheight = g.MeasureString(s, f).Height; RectangleF rect = new RectangleF(new PointF(_p2.X - textwidth / 2, _p2.Y - textheight / 2), new SizeF(textwidth, textheight)); g.FillRectangle(Brushes.White, rect); g.DrawString(s, f, Brushes.Black, _p2, myformat); }
public static void Draw(this Graphics graphics, DrawRecord record) { var width = record.Width; var brush = new SolidBrush(record.Color.ToDrawingColor()); var pen = new Pen(brush, width); //pen.StartCap = LineCap.Square; //pen.MiterLimit = 0.1f; if (record.LineStyle == LineStyles.Dashed) { pen.DashStyle = DashStyle.Dash; } else if (record.LineStyle == LineStyles.Dotted) { pen.DashStyle = DashStyle.Dot; } switch (record.Shape) { case DrawShapes.Curve: //pen.EndCap = LineCap.Square; graphics.DrawCurve(pen, record.Points.Select(p => new Point((int)p.X, (int)p.Y)).ToArray()); break; case DrawShapes.Ellipse: if (record.Mode == DrawModes.Stroke) { graphics.DrawEllipse(pen, record.Rect.ToDrawingRectangle()); } else if (record.Mode == DrawModes.Fill) { graphics.FillEllipse(brush, record.Rect.ToDrawingRectangle()); } break; case DrawShapes.Line: //pen.EndCap = LineCap.Square; graphics.DrawLine(pen, record.Start.ToDrawingPoint(), record.End.ToDrawingPoint()); break; case DrawShapes.Rectangle: if (record.Mode == DrawModes.Stroke) { graphics.DrawRectangle(pen, record.Rect.ToDrawingRectangle()); } else if (record.Mode == DrawModes.Fill) { graphics.FillRectangle(brush, record.Rect.ToDrawingRectangle()); } break; case DrawShapes.Polygon: if (record.Mode == DrawModes.Stroke) { graphics.DrawPolygon(pen, record.Points.Take(record.Points.Count - 1).Select(p => p.ToDrawingPoint()).ToArray()); } else if (record.Mode == DrawModes.Fill) { graphics.FillPolygon(brush, record.Points.Take(record.Points.Count - 1).Select(p => p.ToDrawingPoint()).ToArray()); } break; case DrawShapes.Text: if (string.IsNullOrWhiteSpace(record.Text)) { return; } graphics.DrawString(record.Text, record.TextFont, new SolidBrush(record.Color.ToDrawingColor()), record.Start.ToDrawingPoint()); break; case DrawShapes.Arrow: int arrowSize; switch (record.Distance) { case 5: case 4: arrowSize = 2; break; case 3: case 2: case 1: arrowSize = 1; break; default: arrowSize = 5; break; } var cap = new AdjustableArrowCap(arrowSize, arrowSize, false); pen.CustomEndCap = cap; graphics.DrawLine(pen, record.Start.ToDrawingPoint(), record.End.ToDrawingPoint()); break; } pen.Dispose(); brush.Dispose(); graphics.Flush(); GC.Collect(); }
private void PintaAristasAfd(Graphics g) { if (AfdNodos == null) { return; } AdjustableArrowCap finfle = new AdjustableArrowCap(5, 5); _plumaFlecha.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; _plumaFlecha.CustomEndCap = finfle; int incurv = 0, inletr1 = 0, inletr2 = 0, inletr3 = 0, inletr4 = 0; int inletr1r = 0, inletr2r = 0, inletr3r = 0, inletr4r = 0; string letcurv = "", letra1 = "", letra2 = "", letra3 = "", letra4 = ""; string letra1r = "", letra2r = "", letra3r = "", letra4r = ""; bool band1 = false, band2 = false, band3 = false, band4 = false; int tam = 0, tam2 = 0; int tamafue1 = 0, tamafue1a = 0; int tamafue2 = 0, tamafue2a = 0; int tamafue3 = 0, tamafue3a = 0; int tamafue4 = 0, tamafue4a = 0; for (int i = 0; i < AfdNodos.Count; i++) { for (int j = 0; j < AfdNodos[i].Aristas.Count; j++) { //HazFlechas(AfdNodos[i], AfdNodos[i].Aristas[j].Nodo); tam = ((AfdNodos[i].X) + (AfdNodos[i].Aristas[j].Nodo.X)); tam2 = ((AfdNodos[i].Y) + (AfdNodos[i].Aristas[j].Nodo.Y)); //c hacia adelante y hacia arriba if (AfdNodos[i].X <AfdNodos[i].Aristas[j].Nodo.X && AfdNodos[i].Y> AfdNodos[i].Aristas[j].Nodo.Y) { g.DrawLine(_plumaFlecha, AfdNodos[i].X + 20, AfdNodos[i].Y + 20, AfdNodos[i].Aristas[j].Nodo.X + 5, AfdNodos[i].Aristas[j].Nodo.Y + 30); if (AfdNodos[i].Id > AfdNodos[i].Aristas[j].Nodo.Id) { for (int m = 0; m < AfdNodos[i].Aristas[j].Nodo.Aristas.Count; m++) { if (AfdNodos[i].Aristas[j].Nodo.Aristas[m].Nodo.Id == AfdNodos[i].Id) { band1 = true; } } } if (band1) { if (letra1r == "") { letra1r = AfdNodos[i].Aristas[j].Id.ToString(); } else { letra1r = letra1r + "," + AfdNodos[i].Aristas[j].Id.ToString(); inletr1r++; } } else { if (letra1 == "") { letra1 = AfdNodos[i].Aristas[j].Id.ToString(); } else { letra1 = letra1 + "," + AfdNodos[i].Aristas[j].Id.ToString(); inletr1++; } } tamafue1 = tam; tamafue1a = tam2; } //c hacia atras y hacia arriba if (AfdNodos[i].X > AfdNodos[i].Aristas[j].Nodo.X && AfdNodos[i].Y > AfdNodos[i].Aristas[j].Nodo.Y) { g.DrawLine(_plumaFlecha, AfdNodos[i].X + 20, AfdNodos[i].Y + 20, AfdNodos[i].Aristas[j].Nodo.X + 30, AfdNodos[i].Aristas[j].Nodo.Y + 30); if (AfdNodos[i].Id > AfdNodos[i].Aristas[j].Nodo.Id) { for (int m = 0; m < AfdNodos[i].Aristas[j].Nodo.Aristas.Count; m++) { if (AfdNodos[i].Aristas[j].Nodo.Aristas[m].Nodo.Id == AfdNodos[i].Id) { band2 = true; } } } if (band2) { if (letra2r == "") { letra2r = AfdNodos[i].Aristas[j].Id.ToString(); } else { letra2r = letra2r + "," + AfdNodos[i].Aristas[j].Id.ToString(); inletr2r++; } } else { if (letra2 == "") { letra2 = AfdNodos[i].Aristas[j].Id.ToString(); } else { letra2 = letra2 + "," + AfdNodos[i].Aristas[j].Id.ToString(); inletr2++; } } tamafue2 = tam; tamafue2a = tam2; } // if (AfdNodos[i].X < AfdNodos[i].Aristas[j].Nodo.X && AfdNodos[i].Y < AfdNodos[i].Aristas[j].Nodo.Y) { g.DrawLine(_plumaFlecha, AfdNodos[i].X + 20, AfdNodos[i].Y + 20, AfdNodos[i].Aristas[j].Nodo.X + 5, AfdNodos[i].Aristas[j].Nodo.Y + 5); if (AfdNodos[i].Id > AfdNodos[i].Aristas[j].Nodo.Id) { for (int m = 0; m < AfdNodos[i].Aristas[j].Nodo.Aristas.Count; m++) { if (AfdNodos[i].Aristas[j].Nodo.Aristas[m].Nodo.Id == AfdNodos[i].Id) { band3 = true; } } } if (band3) { if (letra3r == "") { letra3r = AfdNodos[i].Aristas[j].Id.ToString(); } else { letra3r = letra3r + "," + AfdNodos[i].Aristas[j].Id.ToString(); inletr3r++; } } else { if (letra3 == "") { letra3 = AfdNodos[i].Aristas[j].Id.ToString(); } else { letra3 = letra3 + "," + AfdNodos[i].Aristas[j].Id.ToString(); inletr3++; } } tamafue3 = tam; tamafue3a = tam2; //g.DrawString(AfdNodos[i].Aristas[j].Id.ToString(), fuente2, colorprimpos, (int)(tam / 2), (int)(tam2 / 2) + 30); } // if (AfdNodos[i].X > AfdNodos[i].Aristas[j].Nodo.X && AfdNodos[i].Y < AfdNodos[i].Aristas[j].Nodo.Y) { g.DrawLine(_plumaFlecha, AfdNodos[i].X + 20, AfdNodos[i].Y + 20, AfdNodos[i].Aristas[j].Nodo.X + 30, AfdNodos[i].Aristas[j].Nodo.Y + 5); if (AfdNodos[i].X == AfdNodos[i].Aristas[j].Nodo.X + 1) { g.DrawString(AfdNodos[i].Aristas[j].Id.ToString(), fuente2, colorprimpos, (int)(tam / 2), (int)(tam2 / 2) + 30); } else { if (letra4 == "") { letra4 = AfdNodos[i].Aristas[j].Id.ToString(); } else { letra4 = letra4 + "," + AfdNodos[i].Aristas[j].Id.ToString(); inletr4++; } tamafue4 = tam; tamafue4a = tam2; } //g.DrawString(AfdNodos[i].Aristas[j].Id.ToString(), fuente2, colorprimpos, (int)(tam / 2), (int)(tam2 / 2) + 30); } //Igualdades que casi no existen, posible omitir las en y if (AfdNodos[i].X == AfdNodos[i].Aristas[j].Nodo.X && AfdNodos[i].Y > AfdNodos[i].Aristas[j].Nodo.Y) { g.DrawLine(_plumaFlecha, AfdNodos[i].X + 20, AfdNodos[i].Y + 20, AfdNodos[i].Aristas[j].Nodo.X + 15, AfdNodos[i].Aristas[j].Nodo.Y + 30); g.DrawString(AfdNodos[i].Aristas[j].Id.ToString(), fuente2, colorprimpos, (int)(tam / 2), (int)(tam2 / 2) + 30); } if (AfdNodos[i].X == AfdNodos[i].Aristas[j].Nodo.X && AfdNodos[i].Y < AfdNodos[i].Aristas[j].Nodo.Y) { g.DrawLine(_plumaFlecha, AfdNodos[i].X + 20, AfdNodos[i].Y + 20, AfdNodos[i].Aristas[j].Nodo.X + 15, AfdNodos[i].Aristas[j].Nodo.Y); g.DrawString(AfdNodos[i].Aristas[j].Id.ToString(), fuente2, colorprimpos, (int)(tam / 2), (int)(tam2 / 2) + 30); } if (AfdNodos[i].X < AfdNodos[i].Aristas[j].Nodo.X && AfdNodos[i].Y == AfdNodos[i].Aristas[j].Nodo.Y) { g.DrawLine(_plumaFlecha, AfdNodos[i].X + 20, AfdNodos[i].Y + 20, AfdNodos[i].Aristas[j].Nodo.X - 5, AfdNodos[i].Aristas[j].Nodo.Y + 15); g.DrawString(AfdNodos[i].Aristas[j].Id.ToString(), fuente2, colorprimpos, (int)(tam / 2), (int)(tam2 / 2) + 30); } if (AfdNodos[i].X > AfdNodos[i].Aristas[j].Nodo.X && AfdNodos[i].Y == AfdNodos[i].Aristas[j].Nodo.Y) { g.DrawLine(_plumaFlecha, AfdNodos[i].X + 20, AfdNodos[i].Y + 20, AfdNodos[i].Aristas[j].Nodo.X + 35, AfdNodos[i].Aristas[j].Nodo.Y + 15); g.DrawString(AfdNodos[i].Aristas[j].Id.ToString(), fuente2, colorprimpos, (int)(tam / 2), (int)(tam2 / 2) + 30); } if (AfdNodos[i].Id.ToString() == AfdNodos[i].Aristas[j].Nodo.Id.ToString()) { if (letcurv == "") { letcurv = AfdNodos[i].Aristas[j].Id.ToString(); } else { letcurv = letcurv + "," + AfdNodos[i].Aristas[j].Id.ToString(); } incurv++; } if (incurv != 0) { creaVuelta(AfdNodos[i], g, 1); g.DrawString(letcurv, fuente2, coloranul, AfdNodos[i].X - (curva * 2) - 10, AfdNodos[i].Y - 23); } g.DrawString(letra1, fuente2, colorprimpos, (int)(tamafue1 / 2), (int)(tamafue1a / 2) + 30); g.DrawString(letra2, fuente2, colorprimpos, (int)(tamafue2 / 2), (int)(tamafue2a / 2) + 30); g.DrawString(letra3, fuente2, colorprimpos, (int)(tamafue3 / 2), (int)(tamafue3a / 2) + 30); g.DrawString(letra4, fuente2, colorprimpos, (int)(tamafue4 / 2), (int)(tamafue4a / 2) + 30); if (band1) { g.DrawString(letra1r, fuente2, colorprimpos, (int)(tamafue1 / 2), (int)(tamafue1a / 2) + 40); } if (band2) { g.DrawString(letra2r, fuente2, colorprimpos, (int)(tamafue2 / 2), (int)(tamafue2a / 2) + 40); } if (band3) { g.DrawString(letra3r, fuente2, colorprimpos, (int)(tamafue3 / 2), (int)(tamafue3a / 2) + 40); } if (band4) { g.DrawString(letra4r, fuente2, colorprimpos, (int)(tamafue4 / 2), (int)(tamafue4a / 2) + 40); } } band1 = false; band2 = false; band3 = false; band4 = false; incurv = 0; inletr2 = 0; inletr1 = 0; inletr3 = 0; inletr4 = 0; letcurv = ""; letra1 = ""; letra2 = ""; letra3 = ""; letra4 = ""; dibuja(AfdNodos[i], g); } _graphics.DrawRectangle(pincelbl, 20, 20, 51, 51); _graphics.FillRectangle(colorbl, 20, 20, 50, 50); }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // Clear background e.Graphics.Clear(SystemColors.Control); // Draw each part Point selection = (Point)this.anchorEdgeToXy[this.anchorEdge]; double controlCenterX = (double)this.Width / 2.0; double controlCenterY = (double)this.Height / 2.0; Pen linePen = new Pen(SystemColors.WindowText, (((float)Width + (float)Height) / 2.0f) / 64.0f); AdjustableArrowCap cap = new AdjustableArrowCap((float)Width / 32.0f, (float)Height / 32.0f, true); linePen.CustomEndCap = cap; Point mousePoint = PointToClient(Control.MousePosition); int mouseAnchorX = (int)Math.Floor(((float)mousePoint.X * 3.0f) / (float)this.Width); int mouseAnchorY = (int)Math.Floor(((float)mousePoint.Y * 3.0f) / (float)this.Height); for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { AnchorEdge edge = this.xyToAnchorEdge[y][x]; Point offset = (Point)this.anchorEdgeToXy[edge]; Point vector = new Point(offset.X - selection.X, offset.Y - selection.Y); int left = (this.Width * x) / 3; int top = (this.Height * y) / 3; int right = Math.Min(this.Width - 1, (this.Width * (x + 1)) / 3); int bottom = Math.Min(this.Height - 1, (this.Height * (y + 1)) / 3); int width = right - left; int height = bottom - top; if (vector.X == 0 && vector.Y == 0) { ButtonRenderer.DrawButton(e.Graphics, new Rectangle(left, top, width, height), PushButtonState.Pressed); e.Graphics.DrawImage(this.centerImage, left + 3, top + 3, width - 6, height - 6); } else { PushButtonState state; if (drawHotPush && x == this.hotAnchorButton.X && y == this.hotAnchorButton.Y) { state = PushButtonState.Pressed; } else { state = PushButtonState.Normal; if (!mouseDown && mouseAnchorX == x && mouseAnchorY == y) { state = PushButtonState.Hot; } } ButtonRenderer.DrawButton(e.Graphics, new Rectangle(left, top, width, height), state); if (vector.X <= 1 && vector.X >= -1 && vector.Y <= 1 && vector.Y >= -1) { double vectorMag = Math.Sqrt((double)((vector.X * vector.X) + (vector.Y * vector.Y))); double normalX = (double)vector.X / vectorMag; double normalY = (double)vector.Y / vectorMag; Point center = new Point((left + right) / 2, (top + bottom) / 2); Point start = new Point(center.X - (width / 4) * vector.X, center.Y - (height / 4) * vector.Y); Point end = new Point( start.X + (int)(((double)width / 2.0) * normalX), start.Y + (int)(((double)height / 2.0) * normalY)); PixelOffsetMode oldPOM = e.Graphics.PixelOffsetMode; e.Graphics.PixelOffsetMode = PixelOffsetMode.Half; e.Graphics.DrawLine(linePen, start, end); e.Graphics.PixelOffsetMode = oldPOM; } } } } linePen.Dispose(); base.OnPaint(e); }
private const int YTextPixelOffset = 30;//80; //这里是创建一个画布 private void ReDrawAll() { Bitmap bmp = new Bitmap(this.panel2.Width, this.panel2.Height); Graphics g = Graphics.FromImage(bmp); g.Clear(this.panel2.BackColor); //Graphics g = this.CreateGraphics(); //Graphics g = this.panel2.CreateGraphics(); g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿 g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; GObject CurrObj = new GObject(); Rectangle Rct = new Rectangle(); //Pen p = new Pen(Color.Blue); Image ObjImg; int xm = 0; int ym = 0; string IsLine = ""; //for (int i = 0; i < GNetwork.Nobj; i++) //urinatedong 只显示需要显示的 for (int i = 0; i < GNetwork.Nobj; i++) { CurrObj = GNetwork.GObjects[i]; // if (CurrObj.Type == "") { IsLine = "N/D"; } if (CurrObj.Type == "Line") { IsLine = "Y"; } if ((CurrObj.Type != "Line") && (CurrObj.Type != "")) { IsLine = "N"; } // switch (IsLine) { case "Y": // g.DrawLine(p, CurrObj.x1, CurrObj.y1, CurrObj.x2, CurrObj.y2); AdjustableArrowCap lineCap = new AdjustableArrowCap(5, 6, true); Pen p; string[] MyRelationInfo = CurrObj.AddInfo.Split("\n".ToCharArray()); if (MyRelationInfo[6].IndexOf("2") > 0) { p = new Pen(Color.Blue, 3); } else { p = new Pen(Color.Orange, 3); p.DashStyle = DashStyle.Custom; p.DashPattern = new float[] { 6, 3 }; } p.CustomEndCap = lineCap; p.CustomStartCap = lineCap; g.DrawLine(p, CurrObj.x1, CurrObj.y1, CurrObj.x2, CurrObj.y2); xm = (CurrObj.x1 + CurrObj.x2) / 2; ym = (CurrObj.y1 + CurrObj.y2) / 2; //AddText(xm, ym, CurrObj.Name, false,g); int x1 = (CurrObj.x1 + xm) / 2; int y1 = (CurrObj.y1 + ym) / 2; int x2 = (CurrObj.x2 + xm) / 2; int y2 = (CurrObj.y2 + ym) / 2; AddText(x1, y1, MyRelationInfo[0] + "\n" + MyRelationInfo[1] + "\n" + MyRelationInfo[2], false, g); AddText(x2, y2, MyRelationInfo[3] + "\n" + MyRelationInfo[4] + "\n" + MyRelationInfo[5], false, g); p.Dispose(); break; case "N": string[] MyNodeInfo = CurrObj.AddInfo.Split("\n".ToCharArray()); Rct.X = CurrObj.x1; Rct.Y = CurrObj.y1; Rct.Width = CurrObj.x2 - CurrObj.x1; Rct.Height = CurrObj.y2 - CurrObj.y1; if (CurrObj.Type != String.Empty) { if (double.Parse(MyNodeInfo[4].Replace("Battery", "")) > 0) { ObjImg = FindGObjectTypeImage("Router"); } else { ObjImg = FindGObjectTypeImage("NotOnline"); } g.DrawImage(ObjImg, Rct); //使用IP地址显示 //AddText(CurrObj.x1, CurrObj.y1, CurrObj.Name, true,g); AddText(CurrObj.x1, CurrObj.y1, MyNodeInfo[0], true, g); GNetwork.AdjustLinkedTo(CurrObj.Name); } break; } } //g1.DrawEllipse(new Pen(System.Drawing.Color.Red), 10, 10, 100, 100); //g1.DrawImage(Image.FromFile("E:/down.png"), x, 10);//这是在画布上绘制图形 this.panel2.CreateGraphics().DrawImage(bmp, 0, 0);//这句是将图形显示到窗口上 bmp.Dispose(); g.Dispose(); }
private void InitializeStyles() { //Foundational is a blue rectangle with bold black border Foundational = new GraphNodeStyle(); Foundational.points = new Point[4]; Foundational.points[0] = new Point(-50, 23); Foundational.points[1] = new Point(50, 23); Foundational.points[2] = new Point(50, -23); Foundational.points[3] = new Point(-50, -23); Foundational.fillBrush = new SolidBrush(Color.LightSkyBlue); Foundational.font = new Font("Tahoma", 8f, FontStyle.Regular); Foundational.borderPen = new Pen(Color.Black, 2f); Foundational.textBrush = new SolidBrush(Color.Black); Foundational.connectors = new Dictionary <string, Point>(); Foundational.connectors.Add("left", new Point(-50, 0)); Foundational.connectors.Add("right", new Point(50, 0)); Foundational.connectors.Add("top", new Point(0, -23)); Foundational.connectors.Add("bottom", new Point(0, 23)); //Topical is a salmon parallelogram with a regular black border Topical = new GraphNodeStyle(); Topical.points = new Point[4]; Topical.points[0] = new Point(-46, 23); Topical.points[1] = new Point(54, 23); Topical.points[2] = new Point(46, -23); Topical.points[3] = new Point(-54, -23); Topical.fillBrush = new SolidBrush(Color.LightSalmon); Topical.font = new Font("Tahoma", 8f, FontStyle.Regular); Topical.textBrush = new SolidBrush(Color.Black); Topical.borderPen = new Pen(Color.Black, 1f); Topical.connectors = new Dictionary <string, Point>(); Topical.connectors.Add("left", new Point(-50, 0)); Topical.connectors.Add("right", new Point(50, 0)); Topical.connectors.Add("top", new Point(0, -23)); Topical.connectors.Add("bottom", new Point(0, 23)); //Specialized is a green 6-pointed star-like shape with a regular black border Specialized = new GraphNodeStyle(); Specialized.points = new Point[12]; Specialized.points[0] = new Point(-15, 21); Specialized.points[1] = new Point(0, 25); Specialized.points[2] = new Point(15, 21); Specialized.points[3] = new Point(52, 21); Specialized.points[4] = new Point(46, 0); Specialized.points[5] = new Point(52, -21); Specialized.points[6] = new Point(15, -21); Specialized.points[7] = new Point(0, -25); Specialized.points[8] = new Point(-15, -21); Specialized.points[9] = new Point(-52, -21); Specialized.points[10] = new Point(-46, 0); Specialized.points[11] = new Point(-52, 21); Specialized.fillBrush = new SolidBrush(Color.LightGreen); Specialized.font = new Font("Tahoma", 8f, FontStyle.Regular); Specialized.textBrush = new SolidBrush(Color.Black); Specialized.borderPen = new Pen(Color.Black, 1f); Specialized.connectors = new Dictionary <string, Point>(); Specialized.connectors.Add("left", new Point(-46, 0)); Specialized.connectors.Add("right", new Point(46, 0)); Specialized.connectors.Add("top", new Point(0, -25)); Specialized.connectors.Add("bottom", new Point(0, 25)); //Technology is yellow ellipse with a regular black border Technology = new GraphNodeStyle(); Technology.ellipse = true; Technology.fillBrush = new SolidBrush(Color.LemonChiffon); Technology.font = new Font("Tahoma", 8f, FontStyle.Regular); Technology.textBrush = new SolidBrush(Color.Black); Technology.borderPen = new Pen(Color.Black, 1f); Technology.connectors = new Dictionary <string, Point>(); Technology.connectors.Add("left", new Point(-50, 0)); Technology.connectors.Add("right", new Point(50, 0)); Technology.connectors.Add("top", new Point(0, 23)); Technology.connectors.Add("bottom", new Point(0, -23)); //Archival is a gray ellipse with a white border Archival = new GraphNodeStyle(); Archival.ellipse = true; Archival.fillBrush = new SolidBrush(Color.LightGray); Archival.font = new Font("Tahoma", 8f, FontStyle.Regular); Archival.textBrush = new SolidBrush(Color.Black); Archival.borderPen = new Pen(Color.White, 1f); Archival.connectors = new Dictionary <string, Point>(); Archival.connectors.Add("left", new Point(-50, 0)); Archival.connectors.Add("right", new Point(50, 0)); Archival.connectors.Add("top", new Point(0, -23)); Archival.connectors.Add("bottom", new Point(0, 23)); //Prereq edge style is a solid black arrow PrereqEdgeStyle = new Pen(Color.Black, 1f); AdjustableArrowCap cap = new AdjustableArrowCap(5f, 5f, true); cap.BaseInset = 5; cap.StrokeJoin = LineJoin.Bevel; PrereqEdgeStyle.EndCap = LineCap.Custom; PrereqEdgeStyle.CustomEndCap = cap; PrereqEdgeStyle.Width = 2f; //Grantreq edge style is a yellow-green dashed arrow GrantreqEdgeStyle = new Pen(Color.YellowGreen, 1f); GrantreqEdgeStyle.EndCap = LineCap.Custom; GrantreqEdgeStyle.CustomEndCap = cap; GrantreqEdgeStyle.DashStyle = DashStyle.Dash; GrantreqEdgeStyle.Width = 2f; //Initialize dictionary nodeStyles = new Dictionary <string, GraphNodeStyle>(); nodeStyles.Add("Foundational", Foundational); nodeStyles.Add("Topical", Topical); nodeStyles.Add("Specialized", Specialized); nodeStyles.Add("Technologies", Technology); nodeStyles.Add("Archival", Archival); }
private void Panel1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; string DrawChar = ""; Font font = new Font("幼圆", 15); Point hpoint = new Point(20, 40); Point tpoint = new Point(0, 0); Pen pen = new Pen(Color.Tomato, 1); Pen pen1 = new Pen(Color.Green, 1); AdjustableArrowCap arrow = new AdjustableArrowCap(2, 2, false); pen.CustomEndCap = arrow; pen1.CustomEndCap = arrow; int step = 60; switch (drawmode) { case DrawMode.Link: DrawChar += "_head"; g.DrawString(DrawChar, font, Brushes.Teal, hpoint.X - 5, hpoint.Y - 10); hpoint.X += 100; for (int i = 0; i < DrawStr.Length; i++) { if (step > 0) { DrawChar = ""; DrawChar += DrawStr[i]; g.DrawLine(pen, hpoint.X - 46, hpoint.Y, hpoint.X - 20, hpoint.Y); g.DrawRectangle(Pens.Turquoise, hpoint.X - 20, hpoint.Y - 20, 28, 40); g.DrawRectangle(Pens.Turquoise, hpoint.X + 8, hpoint.Y - 20, 12, 40); g.DrawString(DrawChar, font, Brushes.Teal, hpoint.X - 16, hpoint.Y - 10); hpoint.X += step; } else { DrawChar = ""; DrawChar += DrawStr[i]; g.DrawLine(pen, hpoint.X + 46, hpoint.Y, hpoint.X + 20, hpoint.Y); g.DrawRectangle(Pens.Turquoise, hpoint.X - 20, hpoint.Y - 20, 12, 40); g.DrawRectangle(Pens.Turquoise, hpoint.X - 8, hpoint.Y - 20, 28, 40); g.DrawString(DrawChar, font, Brushes.Teal, hpoint.X - 4, hpoint.Y - 10); hpoint.X += step; } if (hpoint.X + step / 2 > Panel1.Width && i + 1 < DrawStr.Length) { step = -60; hpoint.X += step; hpoint.Y += 60; DrawChar = ""; DrawChar += DrawStr[++i]; g.DrawRectangle(Pens.Turquoise, hpoint.X - 20, hpoint.Y - 20, 12, 40); g.DrawRectangle(Pens.Turquoise, hpoint.X - 8, hpoint.Y - 20, 28, 40); g.DrawString(DrawChar, font, Brushes.Teal, hpoint.X - 4, hpoint.Y - 10); g.DrawLine(pen, hpoint.X + 14, hpoint.Y - 60, hpoint.X + 14, hpoint.Y - 20); hpoint.X += step; } if (hpoint.X + step / 2 < 0 && i + 1 < DrawStr.Length) { step = 60; hpoint.X += step; hpoint.Y += 60; DrawChar = ""; DrawChar += DrawStr[++i]; g.DrawRectangle(Pens.Turquoise, hpoint.X - 20, hpoint.Y - 20, 28, 40); g.DrawRectangle(Pens.Turquoise, hpoint.X + 8, hpoint.Y - 20, 12, 40); g.DrawString(DrawChar, font, Brushes.Teal, hpoint.X - 16, hpoint.Y - 10); g.DrawLine(pen, hpoint.X - 14, hpoint.Y - 60, hpoint.X - 14, hpoint.Y - 20); hpoint.X += step; } } if (step > 0) { g.DrawLine(pen, hpoint.X - 46, hpoint.Y, hpoint.X - 20, hpoint.Y); DrawChar = "null"; g.DrawString(DrawChar, font, Brushes.Teal, hpoint.X - 20, hpoint.Y - 10); } else { g.DrawLine(pen, hpoint.X + 46, hpoint.Y, hpoint.X + 20, hpoint.Y); DrawChar = "null"; g.DrawString(DrawChar, font, Brushes.Teal, hpoint.X - 20, hpoint.Y - 10); } break; case DrawMode.Circular: DrawChar += "_head"; g.DrawString(DrawChar, font, Brushes.Purple, hpoint.X - 5, hpoint.Y - 20); hpoint.X += 100; tpoint = hpoint; for (int i = 0; i < DrawStr.Length; i++) { if (step > 0) { DrawChar = ""; DrawChar += DrawStr[i]; g.DrawLine(pen, hpoint.X - 46, hpoint.Y, hpoint.X - 20, hpoint.Y); g.DrawRectangle(Pens.Orchid, hpoint.X - 20, hpoint.Y - 20, 28, 40); g.DrawRectangle(Pens.Orchid, hpoint.X + 8, hpoint.Y - 20, 12, 40); g.DrawString(DrawChar, font, Brushes.Purple, hpoint.X - 16, hpoint.Y - 10); hpoint.X += step; } else { DrawChar = ""; DrawChar += DrawStr[i]; g.DrawLine(pen, hpoint.X + 46, hpoint.Y, hpoint.X + 20, hpoint.Y); g.DrawRectangle(Pens.Orchid, hpoint.X - 20, hpoint.Y - 20, 12, 40); g.DrawRectangle(Pens.Orchid, hpoint.X - 8, hpoint.Y - 20, 28, 40); g.DrawString(DrawChar, font, Brushes.Purple, hpoint.X - 4, hpoint.Y - 10); hpoint.X += step; } if (hpoint.X + step / 2 > Panel1.Width && i + 1 < DrawStr.Length) { step = -60; hpoint.X += step; hpoint.Y += 60; DrawChar = ""; DrawChar += DrawStr[++i]; g.DrawRectangle(Pens.Orchid, hpoint.X - 20, hpoint.Y - 20, 12, 40); g.DrawRectangle(Pens.Orchid, hpoint.X - 8, hpoint.Y - 20, 28, 40); g.DrawString(DrawChar, font, Brushes.Purple, hpoint.X - 4, hpoint.Y - 10); g.DrawLine(pen, hpoint.X + 14, hpoint.Y - 60, hpoint.X + 14, hpoint.Y - 20); hpoint.X += step; } if (hpoint.X + step / 2 < 0 && i + 1 < DrawStr.Length) { step = 60; hpoint.X += step; hpoint.Y += 60; DrawChar = ""; DrawChar += DrawStr[++i]; g.DrawRectangle(Pens.Orchid, hpoint.X - 20, hpoint.Y - 20, 28, 40); g.DrawRectangle(Pens.Orchid, hpoint.X + 8, hpoint.Y - 20, 12, 40); g.DrawString(DrawChar, font, Brushes.Purple, hpoint.X - 16, hpoint.Y - 10); g.DrawLine(pen, hpoint.X - 14, hpoint.Y - 60, hpoint.X - 14, hpoint.Y - 20); hpoint.X += step; } } hpoint.X -= step; if (step > 0) { if (DrawStr.Length == 0) { g.DrawLine(pen, hpoint.X - 46, hpoint.Y, hpoint.X - 20, hpoint.Y); g.DrawLine(pen, hpoint.X - 20, hpoint.Y, hpoint.X + 40, hpoint.Y); hpoint.X += step; DrawChar = "null"; g.DrawString(DrawChar, font, Brushes.Purple, hpoint.X - 20, hpoint.Y - 10); } else { g.DrawLine(pen, hpoint.X + 14, hpoint.Y, hpoint.X + 14, hpoint.Y + 30); g.DrawLine(pen, hpoint.X + 14, hpoint.Y + 30, 30, hpoint.Y + 30); g.DrawLine(pen, 30, hpoint.Y + 30, 30, tpoint.Y + 10); g.DrawLine(pen, 30, tpoint.Y + 10, tpoint.X - 20, tpoint.Y + 10); } } else { g.DrawLine(pen, hpoint.X - 14, hpoint.Y, 30, hpoint.Y); g.DrawLine(pen, 30, hpoint.Y, 30, tpoint.Y + 10); g.DrawLine(pen, 30, tpoint.Y + 10, tpoint.X - 20, tpoint.Y + 10); } break; case DrawMode.Double: DrawChar += "_head"; g.DrawString(DrawChar, font, Brushes.DodgerBlue, hpoint.X - 5, hpoint.Y + 6); hpoint.X += 100; tpoint = hpoint; for (int i = 0; i < DrawStr.Length; i++) { if (step > 0) { DrawChar = ""; DrawChar += DrawStr[i]; g.DrawLine(pen, hpoint.X - 46, hpoint.Y + 14, hpoint.X - 20, hpoint.Y + 14); g.DrawLine(pen1, hpoint.X - 14, hpoint.Y - 14, hpoint.X - 40, hpoint.Y - 14); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X - 20, hpoint.Y - 20, 40, 40); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X - 20, hpoint.Y - 20, 12, 12); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X + 8, hpoint.Y + 8, 12, 12); g.DrawString(DrawChar, font, Brushes.DodgerBlue, hpoint.X - 16, hpoint.Y - 10); hpoint.X += step; } else { DrawChar = ""; DrawChar += DrawStr[i]; g.DrawLine(pen, hpoint.X + 46, hpoint.Y + 14, hpoint.X + 20, hpoint.Y + 14); g.DrawLine(pen1, hpoint.X + 14, hpoint.Y - 14, hpoint.X + 40, hpoint.Y - 14); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X - 20, hpoint.Y - 20, 40, 40); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X - 20, hpoint.Y + 8, 12, 12); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X + 8, hpoint.Y - 20, 12, 12); g.DrawString(DrawChar, font, Brushes.DodgerBlue, hpoint.X - 4, hpoint.Y - 10); hpoint.X += step; } if (hpoint.X + step / 2 > Panel1.Width && i + 1 < DrawStr.Length) { step = -60; hpoint.X += step; hpoint.Y += 60; DrawChar = ""; DrawChar += DrawStr[++i]; g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X - 20, hpoint.Y - 20, 40, 40); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X - 20, hpoint.Y + 8, 12, 12); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X + 8, hpoint.Y - 20, 12, 12); g.DrawString(DrawChar, font, Brushes.DodgerBlue, hpoint.X - 4, hpoint.Y - 10); g.DrawLine(pen, hpoint.X + 12, hpoint.Y - 46, hpoint.X + 12, hpoint.Y - 20); g.DrawLine(pen1, hpoint.X + 16, hpoint.Y - 14, hpoint.X + 16, hpoint.Y - 40); hpoint.X += step; } if (hpoint.X + step / 2 < 0 && i + 1 < DrawStr.Length) { step = 60; hpoint.X += step; hpoint.Y += 60; DrawChar = ""; DrawChar += DrawStr[++i]; g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X - 20, hpoint.Y - 20, 40, 40); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X - 20, hpoint.Y - 20, 12, 12); g.DrawRectangle(Pens.DeepSkyBlue, hpoint.X + 8, hpoint.Y + 8, 12, 12); g.DrawString(DrawChar, font, Brushes.DodgerBlue, hpoint.X - 16, hpoint.Y - 10); g.DrawLine(pen, hpoint.X - 12, hpoint.Y - 46, hpoint.X - 12, hpoint.Y - 20); g.DrawLine(pen1, hpoint.X - 16, hpoint.Y - 14, hpoint.X - 16, hpoint.Y - 40); hpoint.X += step; } } if (step > 0) { g.DrawLine(pen, hpoint.X - 46, hpoint.Y + 14, hpoint.X - 20, hpoint.Y + 14); DrawChar = "null"; g.DrawString(DrawChar, font, Brushes.DodgerBlue, hpoint.X - 20, hpoint.Y + 6); } else { g.DrawLine(pen, hpoint.X + 46, hpoint.Y + 14, hpoint.X + 20, hpoint.Y + 14); DrawChar = "null"; g.DrawString(DrawChar, font, Brushes.DodgerBlue, hpoint.X - 20, hpoint.Y + 6); } if (DrawStr.Length == 0) { break; } g.DrawLine(pen1, tpoint.X - 14, tpoint.Y - 14, tpoint.X - 40, tpoint.Y - 14); DrawChar = "null"; g.DrawString(DrawChar, font, Brushes.DodgerBlue, tpoint.X - 90, tpoint.Y - 20); break; case DrawMode.None: g.Clear(this.BackColor); break; default: break; } }
/// <summary> /// Draws lines between boxes /// </summary> /// <param name="a">First node (From)</param> /// <param name="b">Second Node (To)</param> /// <param name="whichKid">The number of the child node being connected to.</param> /// <param name="kidCount">Number of kids being connected to from the first node.</param> private void joinNodes(Node a, Node b, int whichKid, int kidCount) { PointF[] points = null; float dx, dy, x1, y1, x2, y2; Node temp; Options.ElementOptions eo; eo = Options.OptionsData.whichOption(b); // the second node determines the line style if ((treeOrientation == DrawTree.treeOrientationType.bottom_up) | (treeOrientation == DrawTree.treeOrientationType.top_down)) { if (a.y > b.y) // swap { temp = b; b = a; a = temp; } } else { if (a.x > b.x) // swap { temp = b; b = a; a = temp; } } // Create pen. Pen pen = new Pen(Color.Black, 1); // calc offset if (treeOrientation == DrawTree.treeOrientationType.top_down) { temp = a; } else { temp = b; } // bool distributeX = false; float gap; float xdif = 0; if (opts.Distributed) { gap = temp.width / (float)(kidCount + 1); if (treeOrientation == DrawTree.treeOrientationType.top_down) { xdif = gap * (float)(whichKid + 1) - temp.width / 2; } else { xdif = -(gap * (float)(whichKid + 1) - temp.width / 2); } } if ((treeOrientation == DrawTree.treeOrientationType.bottom_up) | (treeOrientation == DrawTree.treeOrientationType.top_down)) { dx = (b.x + b.width / 2) - (a.x + a.width / 2); // x difference dy = (b.y - a.y - a.height) / 2F; // y difference x1 = a.x + a.width / 2F + offsetX; // right side of top box y1 = a.y + a.height + this.offsetY; // bottom of the box x2 = b.x + (b.width / 2.0F) + this.offsetX; // middle of the bottom box y2 = b.y + this.offsetY; // top of bottom box if (opts.Distributed) { if (treeOrientation == DrawTree.treeOrientationType.top_down) { x1 += xdif; dx -= xdif; } else { x2 -= xdif; dx = x2 - x1; } } } else { x1 = a.x + a.width + offsetX; // halfway in x-axis for the top box y1 = a.y + a.height / 2 + this.offsetY; // bottom of the box x2 = b.x + this.offsetX; // left of right box y2 = b.y + b.height / 2F + this.offsetY; // top of bottom box dx = (x2 - x1) / 2; // x difference dy = y2 - y1; // y difference } // Create array of points that define lines to draw. if ((treeOrientation == DrawTree.treeOrientationType.bottom_up) | (treeOrientation == DrawTree.treeOrientationType.top_down)) { if (join == joinType.dogleg || join == joinType.curve) { if (dx == 0F) // If there is no horizontal movement, just draw one line { PointF[] p1 = { new PointF(x1, y1), new PointF(x2, y2) }; points = p1; } else { PointF[] p1 = { new PointF(x1, y1), new PointF(x1, y1 + dy), new PointF(x1 + dx, y1 + dy), new PointF(x2, y2) }; points = p1; } } else if (join == joinType.direct) // joinType.direct - i.e. a straight line { PointF[] p1 = { new PointF(x1, y1), new PointF(x2, y2) }; points = p1; } else if (join == joinType.curve) { } // do nothing else { System.Diagnostics.Debug.Assert(false, "Unknown join type"); } } else // left to right { if (join == joinType.dogleg || join == joinType.curve) { if (dy == 0F) // If there is no vertical movement, just draw one line { PointF[] p1 = { new PointF(x1, y1), new PointF(x2, y2) }; points = p1; } else { PointF[] p1 = { new PointF(x1, y1), new PointF(x1 + dx, y1), new PointF(x1 + dx, y1 + dy), new PointF(x2, y2) }; points = p1; } } else if (join == joinType.direct) // joinType.direct - i.e. a straight line { PointF[] p1 = { new PointF(x1, y1), new PointF(x2, y2) }; points = p1; } else if (join == joinType.curve) { PointF[] p1 = { new PointF(x1, y1), new PointF(x1, y1 + dy), new PointF(x1 + dx, y1 + dy), new PointF(x2, y2) }; points = p1; } else { System.Diagnostics.Debug.Assert(false, "Unknown join type"); } } pen.DashStyle = eo.lineStyle; // add arrow if required if (arrows != arrowType.none) { AdjustableArrowCap myArrow = new AdjustableArrowCap(4, 6, true); if (arrows == arrowType.start | arrows == arrowType.both) { pen.CustomStartCap = myArrow; } if (arrows == arrowType.end | arrows == arrowType.both) { pen.CustomEndCap = myArrow; } } //Draw lines to screen. if (join == joinType.curve) { graphics.DrawBezier(pen, x1, y1, x1, y1 + dy, x1 + dx, y1 + dy, x2, y2); } else { graphics.DrawLines(pen, points); } if (marker != markerType.none) { drawElementMarker(b, join, x2, y2, pen, new SolidBrush(Color.BlueViolet)); } }
public void DrawDirections() { DrawGrid(sarsa.gridWorld); int direction; double min = 0; double max = 0; for (int i = 0; i < sarsa.q.Length; i++) { for (int j = 0; j < sarsa.q[0].Length; j++) { direction = sarsa.getBestDirection(i, j); if (sarsa.q[i][j][direction] > max) { max = sarsa.q[i][j][direction]; } else if (sarsa.q[i][j][direction] < min) { min = sarsa.q[i][j][direction]; } } } Console.WriteLine("qTable Min: " + min); Console.WriteLine("qTable Max: " + max); Bitmap gridBmp = (Bitmap)pictureBox1.Image; Graphics gridGraphics = Graphics.FromImage(gridBmp); double scaled; int arrowHeadSize; int arrowLength; int xStart; int yStart; int xEnd; int yEnd; int imageSize = pictureBox1.Size.Width; int square = imageSize / Sarsa.GRIDSIZE; int fullArrowLength = square; int fullArrowCap = (int)(square / (double)4); Pen p = new Pen(Color.Blue, 1); for (int i = 0; i < sarsa.q.Length; i++) { for (int j = 0; j < sarsa.q[0].Length; j++) { if ((sarsa.gridWorld[i][j] != Sarsa.PENALTY) && (sarsa.gridWorld[i][j] != Sarsa.REWARD)) { direction = sarsa.getBestDirection(i, j); scaled = (sarsa.q[i][j][direction] - min) / (max - min); //0 to 1. arrowHeadSize = (int)Math.Ceiling(scaled * fullArrowCap); arrowLength = (int)Math.Ceiling(scaled * fullArrowLength); switch (direction) { case Sarsa.UP: xStart = j * square + square / 2; xEnd = xStart; yEnd = i * square; yStart = i * square + arrowLength; break; case Sarsa.RIGHT: xStart = j * square; xEnd = j * square + arrowLength; yStart = i * square + square / 2; yEnd = yStart; break; case Sarsa.DOWN: xStart = j * square + square / 2; xEnd = xStart; yStart = i * square; yEnd = i * square + arrowLength; break; case Sarsa.LEFT: xStart = j * square + arrowLength; xEnd = j * square; yStart = i * square + square / 2; yEnd = yStart; break; default: Debug.WriteLine("Error. Invalid direction: " + direction); xStart = 100; yStart = 100; yEnd = 0; xEnd = 0; break; } AdjustableArrowCap bigArrow = new AdjustableArrowCap(arrowHeadSize, arrowHeadSize); p.CustomEndCap = bigArrow; gridGraphics.DrawLine(p, xStart, yStart, xEnd, yEnd); } } } pictureBox1.Image = gridBmp; }
/********************************************************************* * EXPERIMENTAL * I wanted to colour code the connecting links based on its distance. * I havent got it working properly, so commenting out for now. * * NB: Dont like the idea of continually creating new Pen resource. Wonder * how this affect performance? * * * * * // DRAW THE NODE LINK LINES * // * float maxdist = (float)Math.Sqrt((pbCanvas.Height * pbCanvas.Height) + (pbCanvas.Width * pbCanvas.Width)); * * // Calculate colour of link, based on its distance * float ratio = 1.0f - (link.Value.Distance / maxdist); * if (ratio < 0.0) ratio = 0.0f; * if (ratio > 1.0f) ratio = 1.0f; * * Pen colourPen = new Pen(Color.FromArgb((int)((1 - ratio) * 255), (int)(ratio * 255), 0)); * * colourPen.CustomEndCap = deepArrow; * colourPen.Width = 3.0F; * * if (link.Value.Direction == NodeLink.DirectionType.biDirectional) * colourPen.CustomStartCap = deepArrow; * * graphics.DrawLine(colourPen, sN.GetPosition(), eN.GetPosition()); * colourPen.Dispose(); *********************************************************************/ /************************************************************************** * Renders this line to the screen ***************************************************************************/ public void Draw(ref Graphics graphics, bool showlabels = true) { // graphic objects using (Font labelFont = new Font("Tahoma", 10.0F)) using (Brush labelBrush = new SolidBrush(Color.LightSeaGreen)) using (Brush selectionBrush = new SolidBrush(Color.Gold)) using (Pen linePen = new Pen(Color.MediumAquamarine)) { if (DistType == DistanceType.BlockingDistance) { linePen.Color = Color.FromArgb(128, 128, 128); // Color.FromArgb(76, 90,114); linePen.Width = 3.0F; } else { linePen.Width = 1.5F; AdjustableArrowCap deepArrow = new AdjustableArrowCap(6, 6, true); linePen.CustomEndCap = deepArrow; if (Direction == DirectionType.biDirectional) { linePen.CustomStartCap = deepArrow; } } // Draw line between the two nodes. // We have two options. // The first and easiest is to just draw the line between the two points. // The send option, calculates where the line intersects the node's bounding circle. // We then draw only to that point. // I have tried the first, now I will tackle the second. // get noode points Point sPoint = GetIntersectionPoint(_startPoint, _endPoint); Point ePoint = GetIntersectionPoint(_endPoint, _startPoint); graphics.DrawLine(linePen, sPoint, ePoint); // Draw selection rectangle // If it is auto calculated, then draw an open rectangle. Else draw a // filled rectangle. if (DistType == DistanceType.AutoDistance) { graphics.DrawRectangle(linePen, _selectionRect); } else { graphics.FillRectangle(new SolidBrush(linePen.Color), _selectionRect); } // Draws the path label. This will be the distance between nodes, as stored in the label. // We want our string to be positions midway between the nodes. // // (b) // \[label] // \ // (a) // if (showlabels) { if (Distance != float.MaxValue) { String label = $"{Distance:0.#}"; SizeF labelSize = graphics.MeasureString(label, labelFont); int midX = Math.Abs(ePoint.X - sPoint.X) / 2 + Math.Min(sPoint.X, ePoint.X); int midY = Math.Abs(ePoint.Y - sPoint.Y) / 2 + Math.Min(sPoint.Y, ePoint.Y); Point labelPoint = new Point(midX - (int)labelSize.Width, midY - (int)labelSize.Height); graphics.DrawString(label, labelFont, labelBrush, labelPoint); } } }// using } // Draw
private void startDraw() { double angulo; double radio; int div = graph.getNodesCount(); int x; int y; string nom; Pen pluma1 = new Pen(Color.BlueViolet); Pen pluma2 = new Pen(Color.Red); SolidBrush mensajes = new SolidBrush(Color.White); radio = (graphPanel.Height - 30) / 2; angulo = 2 * Math.PI / div; for (int i = 0; i < graph.getNodesCount(); i++) { x = graph.getNode(i).getCiudad().getPosX(); y = graph.getNode(i).getCiudad().getPosY(); graphPanel.CreateGraphics().DrawEllipse(pluma2, x - 10, y - 10, 20, 20); } int originX = 0; int originY = 0; int destinyX = 0; int destinyY = 0; int letterX = 0; int letterY = 0; string letter; Pen arista = new Pen(Color.BlueViolet, 1); SolidBrush letterPen = new SolidBrush(Color.White); AdjustableArrowCap arrow = new AdjustableArrowCap(3, 5); arista.CustomEndCap = arrow; for (int i = 0; i < graph.getNodesCount(); i++) { for (int j = 0; j < graph.getNode(i).getAdyCount(); j++) { originX = graph.getNode(i).getCiudad().getPosX(); originY = graph.getNode(i).getCiudad().getPosY(); destinyX = graph.getNode(i).getAdyEl(j).getNodo().getCiudad().getPosX(); destinyY = graph.getNode(i).getAdyEl(j).getNodo().getCiudad().getPosY(); this.graphPanel.CreateGraphics().DrawLine(arista, originX, originY, destinyX, destinyY); letterX = (originX + destinyX) / 2; letterY = (originY + destinyY) / 2; letter = graph.getNode(i).getAdyEl(j).getPondCosto() + ", " + graph.getNode(i).getAdyEl(j).getPondTime(); graphPanel.CreateGraphics().DrawString(letter, DefaultFont, letterPen, letterX, letterY); } } for (int i = 0; i < graph.getNodesCount(); i++) { nom = graph.getNode(i).getCiudad().getName().ToString(); x = graph.getNode(i).getCiudad().getPosX(); y = graph.getNode(i).getCiudad().getPosY(); graphPanel.CreateGraphics().DrawString(nom, DefaultFont, mensajes, x - 5, y - 5); } }
public void visualize(ref Bitmap visual, ref Graphics g, ref int[,] Vs, int width, int height, int selected_vertex, int selected_edge, string info_str, bool show_com = false) { g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.Clear(Color.White); int r = 25; //시각화 원 반지름 // ### 간선 그리기 ### for (int j = 1; j <= V; j++) { int v1 = j; int cnt = W[j].Count; for (int i = 0; i < cnt; i++) { int v2 = W[j][i].v; Pen p = new Pen(Color.FromArgb(100, 0, 0, 0), 5); if (preV[v2] == v1) //선택된 경로 { p = new Pen(Color.Orange, 5); } else if (show_com) //완성된 경로만 보이기 { continue; } if (selected_vertex == j && selected_edge == i) { p = new Pen(Color.BlueViolet, 10); } AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 5); //큰 화살표 p.StartCap = LineCap.Round; p.CustomEndCap = bigArrow; double m = (double)(Vs[v1 - 1, 1] - Vs[v2 - 1, 1]) / (double)(Vs[v1 - 1, 0] - Vs[v2 - 1, 0]); double seta = Math.Atan(m); int e = 1; if (Vs[v1 - 1, 0] > Vs[v2 - 1, 0] && Vs[v1 - 1, 1] < Vs[v2 - 1, 1] || Vs[v1 - 1, 0] > Vs[v2 - 1, 0] && Vs[v1 - 1, 1] > Vs[v2 - 1, 1]) { e = -1; //arctan 범위별 조정 } g.DrawLine(p, Vs[v1 - 1, 0], Vs[v1 - 1, 1], Vs[v2 - 1, 0] - (int)(Math.Cos(seta) * r) * e, Vs[v2 - 1, 1] - (int)(Math.Sin(seta) * r) * e); } } // ### 정점 그리기 ### for (int j = 0; j < V; j++) { SolidBrush brush = new SolidBrush(Color.White); if (j == K - 1) { brush = new SolidBrush(Color.Red); } g.FillEllipse(brush, Vs[j, 0] - r, Vs[j, 1] - r, r * 2, r * 2); if (selected_vertex - 1 == j) { g.DrawEllipse(new Pen(Color.BlueViolet, 10), Vs[j, 0] - r, Vs[j, 1] - r, r * 2, r * 2); } else { g.DrawEllipse(new Pen(Color.Black, 5), Vs[j, 0] - r, Vs[j, 1] - r, r * 2, r * 2); } if (j + 1 >= 100) { g.DrawString((j + 1) + "", new Font("나눔고딕", 18), new SolidBrush(Color.Black), Vs[j, 0] - 25, Vs[j, 1] - 15); } else if (j + 1 >= 10) { g.DrawString((j + 1) + "", new Font("나눔고딕", 25), new SolidBrush(Color.Black), Vs[j, 0] - 25, Vs[j, 1] - 20); //g.DrawString((j + 1) + "", new Font("나눔고딕", 9), new SolidBrush(Color.Black), Vs[j, 0] - 9, Vs[j, 1] - 8); } else { g.DrawString((j + 1) + "", new Font("나눔고딕", 30), new SolidBrush(Color.Black), Vs[j, 0] - 20, Vs[j, 1] - 25); //g.DrawString((j + 1) + "", new Font("나눔고딕", 12), new SolidBrush(Color.Black), Vs[j, 0] - 7, Vs[j, 1] - 10); } } Font font = new Font("나눔고딕", 30); // ### Vertext Cost Table 그리기 ### int dw = 150, dh = 60; g.DrawString(" Vertex", font, new SolidBrush(Color.Black), width + dw, dh + 5); g.DrawString(" Cost", font, new SolidBrush(Color.Black), width + dw * 2, dh + 5); g.DrawLine(new Pen(Color.Black, 3), width + dw * 2, dh, width + dw * 2, dh * (V / 2 + 2)); g.DrawLine(new Pen(Color.Black, 3), width + dw, dh, width + dw, dh * (V / 2 + 2)); g.DrawLine(new Pen(Color.Black, 3), width + dw * 3, dh, width + dw * 3, dh * (V / 2 + 2)); g.DrawLine(new Pen(Color.Black, 3), width + dw, dh, width + dw * 3, dh); for (int v = 1; v <= V / 2; v++) { g.DrawString(" " + v, font, new SolidBrush(Color.Black), width + dw, dh * (v + 1) + 5); if (C[v] == -1) { g.DrawString(" ∞", font, new SolidBrush(Color.Black), width + dw * 2, dh * (v + 1) + 5); } else { g.DrawString(" " + C[v], font, new SolidBrush(Color.Black), width + dw * 2, dh * (v + 1) + 5); } g.DrawLine(new Pen(Color.Black, 3), width + dw, dh * (v + 1), width + dw * 3, dh * (v + 1)); } g.DrawLine(new Pen(Color.Black, 3), width + dw, dh * (V / 2 + 2), width + dw * 3, dh * (V / 2 + 2)); //V값이 너무 크기 때문에 두 부분으로 나누어 출력 g.DrawString(" Vertex", font, new SolidBrush(Color.Black), dw * 2 + width + dw, dh + 5); g.DrawString(" Cost", font, new SolidBrush(Color.Black), dw * 2 + width + dw * 2, dh + 5); g.DrawLine(new Pen(Color.Black, 3), dw * 2 + width + dw * 2, dh, dw * 2 + width + dw * 2, dh * (V / 2 + 2)); g.DrawLine(new Pen(Color.Black, 3), dw * 2 + width + dw, dh, dw * 2 + width + dw, dh * (V / 2 + 2)); g.DrawLine(new Pen(Color.Black, 3), dw * 2 + width + dw * 3, dh, dw * 2 + width + dw * 3, dh * (V / 2 + 2)); g.DrawLine(new Pen(Color.Black, 3), dw * 2 + width + dw, dh, dw * 2 + width + dw * 3, dh); for (int v = 1; v <= V / 2; v++) { g.DrawString(" " + (v + V / 2), font, new SolidBrush(Color.Black), dw * 2 + width + dw, dh * (v + 1) + 5); if (C[v + V / 2] == -1) { g.DrawString(" ∞", font, new SolidBrush(Color.Black), dw * 2 + width + dw * 2, dh * (v + 1) + 5); } else { g.DrawString(" " + C[v + V / 2], font, new SolidBrush(Color.Black), dw * 2 + width + dw * 2, dh * (v + 1) + 5); } g.DrawLine(new Pen(Color.Black, 3), dw * 2 + width + dw, dh * (v + 1), dw * 2 + width + dw * 3, dh * (v + 1)); } g.DrawLine(new Pen(Color.Black, 3), dw * 2 + width + dw, dh * (V / 2 + 2), dw * 2 + width + dw * 3, dh * (V / 2 + 2)); // ### HEAP 구조 그리기 ### Bitmap visual_heap = new Bitmap(2000, 1000); pC.visualHeap(ref visual_heap); g.DrawImage(visual_heap, 50, height + 200); font = new Font("나눔고딕", 60); g.DrawString(info_str, font, new SolidBrush(Color.Orange), 50, height + 1800); // 프레임 저장 visual.Save(@"datas\" + frames + ".png", System.Drawing.Imaging.ImageFormat.Png); frames++; }
public virtual void Draw(Graphics g) { if (MenuBox.Right > Map.Right) { MenuBox.X -= MenuBox.Width; } using (SolidBrush shadowBrush = new SolidBrush(Color.FromArgb(100, Color.Black))) { g.FillRectangle(shadowBrush, MenuBox.X + 3, MenuBox.Y + 3, MenuBox.Width, MenuBox.Height); } using (SolidBrush menuBrush = new SolidBrush(MenuColor)) { g.FillRectangle(menuBrush, MenuBox); } using (Pen shadowPen = new Pen(Color.FromArgb(100, Color.Black))) { g.DrawLine(shadowPen, MenuBox.Left, MenuBox.Top, MenuBox.Left, MenuBox.Bottom); g.DrawLine(shadowPen, MenuBox.Left, MenuBox.Top, MenuBox.Right, MenuBox.Top); } foreach (MapMenuOption option in Options) { int optionYPosition = MenuBox.Y + OptionHeight * Options.IndexOf(option); if (option == SelectedOption && option.Selectable) { using (SolidBrush invertMenu = new SolidBrush(FontColor)) { g.FillRectangle(invertMenu, MenuBox.X, optionYPosition, MenuBox.Width, OptionHeight); } using (Font menuFont = new Font(FontFamily, FontSize)) using (SolidBrush invertFont = new SolidBrush(MenuColor)) { g.DrawString(option.Text, menuFont, invertFont, MenuBox.X + XBuffer, optionYPosition); } } else { if (option.Toggled) { using (SolidBrush toggleBrush = new SolidBrush(ToggleColor)) { g.FillRectangle(toggleBrush, MenuBox.X, optionYPosition, MenuBox.Width, OptionHeight); } } using (Font menuFont = new Font(FontFamily, FontSize)) using (SolidBrush fontBrush = new SolidBrush(FontColor)) { g.DrawString(option.Text, menuFont, fontBrush, MenuBox.X + XBuffer, optionYPosition); } } if (option.SubMenu != null) { using (AdjustableArrowCap subArrow = new AdjustableArrowCap(OptionHeight - 12, 3)) using (Pen arrowPen = new Pen(FontColor)) { arrowPen.CustomEndCap = subArrow; if (option == SelectedOption) { arrowPen.Color = MenuColor; } g.SmoothingMode = SmoothingMode.AntiAlias; g.DrawLine(arrowPen, MenuBox.Right - subArrow.Height - 2, optionYPosition + OptionHeight / 2, MenuBox.Right - 2, optionYPosition + OptionHeight / 2); } } } MapMenuOption autoShowSubMenu = null; if (Options.Count(option => option.OptionObject.GetType() == typeof(Battle)) == 1) { autoShowSubMenu = Options.First(option => option.OptionObject.GetType() == typeof(Battle)); } else if (Options.Count(option => option.OptionObject.GetType() == typeof(List <Battle>)) > 0) { autoShowSubMenu = Options.First(option => option.OptionObject.GetType() == typeof(List <Battle>)); } else if (Options.Count(option1 => option1.OptionObject.GetType() == typeof(Site)) == 1) { autoShowSubMenu = Options.First(option1 => option1.OptionObject.GetType() == typeof(Site)); } else if (Options.Count(option1 => option1.OptionObject.GetType() == typeof(War)) == 1) { autoShowSubMenu = Options.First(option1 => option1.OptionObject.GetType() == typeof(War)); } foreach (MapMenuOption option in Options) { int optionYPosition = MenuBox.Y + OptionHeight * Options.IndexOf(option); if (option.SubMenu != null) { if (option == SelectedOption || !Open && (option == autoShowSubMenu || Options.Count == 1)) { option.SubMenu.MenuBox.Location = new Point(MenuBox.Right, optionYPosition); if (option.SubMenu.MenuBox.Right > Map.Right) { option.SubMenu.MenuBox.X = MenuBox.X - option.SubMenu.MenuBox.Width; } option.SubMenu.Draw(g); } } } }
/************************************************************************** * PictureBox paint handler * Responsible for rendering all items on the graph to the screen ***************************************************************************/ private void pbCanvas_Paint(object sender, PaintEventArgs e) { Graphics graphics = e.Graphics; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Pen drawingLinePen = new Pen(Color.Coral); Pen solutionLinePen = new Pen(Color.FromArgb(255, 22, 84)); Pen selectionPen = new Pen(Color.Yellow); // directional pens Pen biDirectionalLinePen = new Pen(Color.MediumAquamarine); Pen uniDirectionalLinePen = new Pen(Color.OliveDrab); AdjustableArrowCap deepArrow = new AdjustableArrowCap(4, 4, false); uniDirectionalLinePen.CustomEndCap = deepArrow; biDirectionalLinePen.CustomStartCap = deepArrow; biDirectionalLinePen.CustomEndCap = deepArrow; biDirectionalLinePen.Width = 2.0F; uniDirectionalLinePen.Width = 2.0F; drawingLinePen.Width = 3.0F; solutionLinePen.Width = 3.0F; // Label graphic objects Font labelFont = new Font("Tahoma", 10.0F); Brush labelBrush = new SolidBrush(Color.LightSeaGreen); // Draw the background grid draw_Grid(ref graphics); foreach (var link in _linkcollection) { link.Value.Draw(ref graphics, _showlabels); } // Draw our nodes foreach (var node in _nodecollection) { node.Value.Draw(ref graphics, _showlabels); } // SOLUTION PATH LINK // If we have a solution path, then draw the lines here, using a different // colour ? if (_endNodeId >= 0) { PathNode currentnode = GetNodeWithId(_endNodeId); if (currentnode != null) { while (currentnode.PreviousNodeId >= 0) { PathNode prevNode = GetNodeWithId(currentnode.PreviousNodeId); if (prevNode == null) { break; } graphics.DrawLine(solutionLinePen, prevNode.GetPosition(), currentnode.GetPosition()); currentnode = prevNode; } } } // Draw connecting lines. // These are dynamic drawing lines that follow the mouse. if (_actionConnectingPath) { String label = null; bool isBothDir = Control.ModifierKeys.HasFlag(Keys.Control); if (isBothDir) { label = "<< >>"; } else { label = ">>"; } SizeF labelSize = graphics.MeasureString(label, labelFont); foreach (var startnodeid in _selectionNodes) { PathNode startnode = _nodecollection[startnodeid]; if (startnode == null) { continue; } Point sP = startnode.GetPosition(); Point eP = _mouseposition; graphics.DrawLine(drawingLinePen, sP, eP); int midX = Math.Abs(eP.X - sP.X) * 4 / 5 + Math.Min(sP.X, eP.X); int midY = Math.Abs(eP.Y - sP.Y) * 4 / 5 + Math.Min(sP.Y, eP.Y); Point labelPoint = new Point(midX - (int)labelSize.Width, midY - (int)labelSize.Height - 10); graphics.DrawString(label, labelFont, labelBrush, labelPoint); } } else { if (_mousedown && _actionSelection) { graphics.DrawRectangle(selectionPen, _selectionrect); } } // clean up solutionLinePen.Dispose(); drawingLinePen.Dispose(); uniDirectionalLinePen.Dispose(); biDirectionalLinePen.Dispose(); labelFont.Dispose(); labelBrush.Dispose(); } // pbCanvas_Paint
private static void DrawDirections(Graphics g, Grid grid, Rectangle bounds, int rowEnd) { int xOrig = bounds.X; int penWidth = bounds.Width / 16; penWidth = penWidth > 0 ? penWidth : 1; int arrowSize = bounds.Width / 9; arrowSize = arrowSize > 0 ? arrowSize : 1; AdjustableArrowCap endCap = new AdjustableArrowCap(arrowSize, arrowSize, true); endCap.WidthScale = 0; int size = grid.Cells.Count; for (int i = 0; i < size; i++) { Cell cell = grid.Cells[i]; int items = cell.Objects.Count; for (int j = 0; j < items; j++) { Item item = cell.Objects[j]; if (item.ID == 0) { continue; } Color penColor; if (items - j == 1) { penColor = Color.Red; } else if (items - j == 2) { penColor = Color.Orange; } else if (items - j == 3) { penColor = Color.Blue; } else if (items - j == 4) { penColor = Color.Gray; } else { penColor = Color.Teal; } using (Pen pen = new Pen(penColor, penWidth)) { int endX = 0; int endY = 0; switch ((Direction)item.Direction) { case Direction.Right: endX = bounds.X + bounds.Width - 1; endY = bounds.Y + bounds.Height / 2; break; case Direction.Up: endX = bounds.X + bounds.Width / 2; endY = bounds.Y; break; case Direction.Left: endX = bounds.X; endY = bounds.Y + bounds.Height / 2; break; case Direction.Down: endX = bounds.X + bounds.Width / 2; endY = bounds.Y + bounds.Height - 1; break; } pen.CustomEndCap = endCap; g.PageUnit = GraphicsUnit.Pixel; g.DrawLine(pen, bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2, endX, endY); } } bounds.X += bounds.Width; if (bounds.X >= rowEnd) { bounds.Y += bounds.Height; bounds.X = xOrig; } } }
public Connector(Canvas canvas) : base(canvas) { adjCapArrow = new AdjustableArrowCap(BaseController.CAP_WIDTH, BaseController.CAP_HEIGHT, true); adjCapDiamond = new AdjustableArrowCap(BaseController.CAP_WIDTH, BaseController.CAP_HEIGHT, true); adjCapDiamond.MiddleInset = -BaseController.CAP_WIDTH; }
//------------------------------------------------------------------------ public override void DrawExpression(CContextDessinObjetGraphique ctx, CRepresentationExpressionGraphique expressionGraphique) { Rectangle rct = expressionGraphique.RectangleAbsolu; if (expressionGraphique.LastErreur != null && expressionGraphique.LastErreur != "") { ctx.Graphic.FillRectangle(Brushes.Red, rct); } else { ctx.Graphic.FillRectangle(Brushes.White, rct); } ctx.Graphic.DrawRectangle(Pens.Black, rct); ctx.Graphic.DrawImageUnscaled(Resources.CActionForEach, rct.Left + 1, rct.Top + 1); C2iExpressionAnalysable expAn = expressionGraphique.Formule as C2iExpressionAnalysable; string strText = "ForEach"; /*if (expAn != null) * strText = expAn.GetInfos().Texte; * else *//*if ( expressionGraphique.Formule != null ) * strText = expressionGraphique.Formule.GetString();*/ StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; Font ft = new Font(FontFamily.GenericSansSerif, 8); ctx.Graphic.DrawString(strText, ft, Brushes.Black, expressionGraphique.RectangleAbsolu, f); AdjustableArrowCap cap = new AdjustableArrowCap(4, 4, true); C2iExpressionGraphique rep = expressionGraphique.RepresentationRacine; if (rep != null) { Pen pen = new Pen(Brushes.Blue, 2); pen.EndCap = LineCap.Custom; pen.CustomEndCap = cap; foreach (string strLien in expressionGraphique.IdElementsUtilises) { CRepresentationExpressionGraphique exp = rep.GetFormule(strLien); if (exp != null) { DrawLien(ctx, pen, ft, expressionGraphique, exp, ""); } } pen.Dispose(); } CRepresentationExpressionGraphique next = expressionGraphique.Next; if (next != null) { Pen pen = new Pen(Brushes.Black, 3); pen.CustomEndCap = cap; DrawLien(ctx, pen, ft, expressionGraphique, next, ""); pen.Dispose(); } cap.Dispose(); ft.Dispose(); }
private void imprimirCiudades(Grafo gf, Pen p3) { int x1, x2, y1, y2; foreach (Nodo n in gf.getListaNodos()) { if (n.getX() >= 0 && n.getY() >= 0) { Pen p2 = new Pen(Color.Blue, 4); panel1.CreateGraphics().DrawEllipse(p2, n.getX(), n.getY(), 50, 50); panel1.CreateGraphics().DrawString(Char.ToString(n.getCiudad()), new Font("Arial", 20), new SolidBrush(Color.Blue), new RectangleF(n.getX() + 10, n.getY() + 10, 50, 50), new StringFormat()); foreach (Ady a in n.getListaAdy()) { if (a.getNodo().getX() >= 0 && a.getNodo().getY() >= 0) { if (n.getY() < a.getNodo().getY()) { y1 = n.getY() + 40; y2 = a.getNodo().getY() + 10; } else { y1 = n.getY() + 10; y2 = a.getNodo().getY() + 40; } if (n.getX() < a.getNodo().getX()) { x1 = n.getX() + 40; x2 = a.getNodo().getX() + 10; panel1.CreateGraphics().DrawString(Convert.ToString("$" + a.getcosto() + "\n" + a.getTiempo() + "min."), new Font("ArialBlack", 10), new SolidBrush(Color.Black), new RectangleF(x1, y1, 50, 50), new StringFormat()); } else { x1 = n.getX() + 10; x2 = a.getNodo().getX() + 40; panel1.CreateGraphics().DrawString(Convert.ToString("$" + a.getcosto() + "\n" + a.getTiempo() + "min."), new Font("ArialBlack", 10), new SolidBrush(Color.Black), new RectangleF(x1 - 50, y1, 50, 50), new StringFormat()); } AdjustableArrowCap bigArrow = new AdjustableArrowCap(7, 7); p3.CustomEndCap = bigArrow; //panel1.CreateGraphics().DrawLine(p3,n.getX() + 25, n.getY() + 25, a.getNodo().getX() + 25, a.getNodo().getY() + 25); panel1.CreateGraphics().DrawLine(p3, x1, y1, x2, y2); } } } } foreach (Nodo n in gf.getListaNodos()) { if (n.getX() <= 1 || n.getY() <= 1) { establecerPosicion(n); break; } } }
private void DrawDialogueItem(Graphics g, CanvasElement ca) { try { //Setup rectangle and pen Rectangle r = new Rectangle( new Point(ca.p.X + camera.X, ca.p.Y + camera.Y), ca.Size ); AdjustableArrowCap cap = new AdjustableArrowCap(4, 4); Pen p = new Pen(Brushes.Black, 2) { CustomEndCap = cap }; if (dialogSystem.items[ca.id].entry) { g.DrawLine( p, 0, r.Y + r.Height / 2, r.X, r.Y + r.Height / 2 ); } for (int i = 0; i < dialogSystem.items[ca.id].options.Count; i++) { if (dialogSystem.items[ca.id].options[i].next == -1) { int x = r.X + r.Width, y = r.Y + r.Height / 2; g.DrawLine( p, x, y, x + r.Width / 4, y ); g.DrawString( "Exit", DefaultFont, Brushes.Black, new Point( x + r.Width / 4 + 4, y - 6 ) ); } else if (dialogSystem.items[ca.id].options[i].next < elements.Count) { CanvasElement target = elements[dialogSystem.items[ca.id].options[i].next]; if (target == null) { continue; } Pen arrowPen = ca.isEvent ? ( i == 0 ? new Pen(Color.Green, 2) { CustomEndCap = cap } : new Pen(Color.Red, 2) { CustomEndCap = cap } ) : p; //Construct source and destination points Point source = new Point( r.X + r.Width, r.Y + r.Height / 2 ); Point destination = new Point( target.p.X + camera.X, target.p.Y + camera.Y + target.Size.Height / 2 ); //Construct curved line points Point[] points = new Point[] { source, new Point( source.X + (int)((float)(destination.X - source.X) * .25), source.Y + (int)((float)(destination.Y - source.Y) * .75) ), destination }; //Draw curved arrow g.DrawCurve(arrowPen, points, .75f); } } //Draw rectangle //Filling g.FillRectangle( ca.isEvent ? Brushes.Silver : Brushes.WhiteSmoke, r ); //Shadow g.DrawLine( new Pen(new SolidBrush(Color.FromArgb(75, 0, 0, 0)), 3), new Point(r.X, r.Y + r.Height), new Point(r.X + r.Width, r.Y + r.Height) ); //Border g.DrawRectangle(Pens.Black, r); //Draw content int padding = 4; int idMargin = 2; int idHeight = 12 + idMargin * 2; //Bold ID g.DrawString( "#" + ca.id, new Font(DefaultFont, FontStyle.Bold), Brushes.Black, new Rectangle( r.X + padding, r.Y + padding, r.Width - padding, idHeight ) ); //Draw text g.DrawString( ca.isEvent ? FormatEventType(dialogSystem.items[ca.id].eventType) : dialogSystem.items[ca.id].text, ca.isEvent ? DefaultFont : new Font(DefaultFont, FontStyle.Italic), Brushes.Black, new Rectangle( r.X + padding, r.Y + padding + idHeight, r.Width - padding, r.Height - padding - idHeight ) ); } catch { //... } }
//panel load do thi private void SanChoi_Paint(object sender, PaintEventArgs e) { if (ready == false) { return; } // But dung de ve mui ten // Pen MuiTenPen = new Pen(Color.Red, 2); //MuiTenPen.StartCap = LineCap.RoundAnchor; //MuiTenPen.EndCap = LineCap.ArrowAnchor; // bút có mũi tên Pen p = new Pen(Color.Blue, 2); AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 5); p.CustomEndCap = bigArrow; // but khong mui ten Pen pen = new Pen(Color.White, 1); Pen penStart = new Pen(Color.Blue, 4); Pen penEnd = new Pen(Color.Yellow, 4); // but : khi chua nhap 2 diem dau va cuoi (Điểm thường) SolidBrush br = new SolidBrush(Color.White); // but : chỉ nhap diem dau SolidBrush brStart = new SolidBrush(Color.GreenYellow); // but : chỉ nhap diem cuoi SolidBrush brEnd = new SolidBrush(Color.Purple); Graphics gr = SanChoi.CreateGraphics(); // Ve duong di truoc if (readyEdges == true && readyPoints == true) { for (int h = 1; h <= numberPoints; h++) { for (int k = 1; k <= numberPoints; k++) { if (MTK[h, k] != 0) { gr.DrawLine(pen, CTD(aPoint[h]), CTD(aPoint[k])); } } } } //Diem render sau if (readyPoints == true) { if (readySP == true && readyEP == false) { for (int i = 1; i <= numberPoints; i++) { if (i == startPoint) { continue; } gr.FillEllipse(br, CTD(aPoint[i]).X - 5, CTD(aPoint[i]).Y - 5, 25, 25); gr.DrawString(i + "", new Font("Consolas", 9), new SolidBrush(Color.Black), CTD(aPoint[i]).X, CTD(aPoint[i]).Y); } // vẽ điểm đầu sau những điểm thường gr.FillEllipse(brStart, CTD(aPoint[startPoint]).X - 5, CTD(aPoint[startPoint]).Y - 5, 25, 25); gr.DrawString(startPoint + "", new Font("Consolas", 9), new SolidBrush(Color.Black), CTD(aPoint[startPoint]).X, CTD(aPoint[startPoint]).Y); } else if (readySP == false && readyEP == true) { for (int i = 1; i <= numberPoints; i++) { if (i == endPoint) { continue; } gr.FillEllipse(br, CTD(aPoint[i]).X - 5, CTD(aPoint[i]).Y - 5, 25, 25); gr.DrawString(i + "", new Font("Consolas", 9), new SolidBrush(Color.Black), CTD(aPoint[i]).X, CTD(aPoint[i]).Y); } // vẽ điểm cuối sau những điểm thường gr.FillEllipse(brEnd, CTD(aPoint[endPoint]).X - 5, CTD(aPoint[endPoint]).Y - 5, 25, 25); gr.DrawString(endPoint + "", new Font("Consolas", 9), new SolidBrush(Color.Black), CTD(aPoint[endPoint]).X, CTD(aPoint[endPoint]).Y); } else if (readySP == true && readyEP == true) { for (int i = 1; i <= numberPoints; i++) { if (i == startPoint || i == endPoint) { continue; } gr.FillEllipse(br, CTD(aPoint[i]).X - 5, CTD(aPoint[i]).Y - 5, 25, 25); gr.DrawString(i + "", new Font("Consolas", 9), new SolidBrush(Color.Black), CTD(aPoint[i]).X, CTD(aPoint[i]).Y); } // vẽ điểm đầu và điểm cuối sau những điểm thường gr.FillEllipse(brStart, CTD(aPoint[startPoint]).X - 5, CTD(aPoint[startPoint]).Y - 5, 25, 25); gr.DrawString(startPoint + "", new Font("Consolas", 9), new SolidBrush(Color.Black), CTD(aPoint[startPoint]).X, CTD(aPoint[startPoint]).Y); gr.FillEllipse(brEnd, CTD(aPoint[endPoint]).X - 5, CTD(aPoint[endPoint]).Y - 5, 25, 25); gr.DrawString(endPoint + "", new Font("Consolas", 9), new SolidBrush(Color.Black), CTD(aPoint[endPoint]).X, CTD(aPoint[endPoint]).Y); } else { for (int i = 1; i <= numberPoints; i++) { gr.FillEllipse(br, CTD(aPoint[i]).X - 5, CTD(aPoint[i]).Y - 5, 25, 25); gr.DrawString(i + "", new Font("Consolas", 9), new SolidBrush(Color.Black), CTD(aPoint[i]).X, CTD(aPoint[i]).Y); } } } if (displayRoad == true && running == true) { int tempSau = endPoint; while (true) { int tempTruoc = history[tempSau].DiemDiToi; gr.DrawLine(p, CTD(aPoint[tempTruoc]), CTD(aPoint[tempSau])); if (tempTruoc == startPoint) { break; } tempSau = tempTruoc; } // displayRoad = false; } if (displayDistances == true) { Point tempPoint = new Point(); for (int i = 1; i <= numberPoints; i++) { for (int j = 1; j <= numberPoints; j++) { if (MTK[i, j] != 0) { tempPoint = TrungDiem(i, j); //Hien thi do dai tai trung diem gr.DrawString(MTK[i, j].ToString(), new Font("Consolas", 8), new SolidBrush(Color.DodgerBlue), CTD(tempPoint)); } } } } // gr.DrawLine(MuiTenPen, CTD(aPoint[1]), CTD(aPoint[2])); //Graphics g = e.Graphics; ////g.SmoothingMode = SmoothingMode.AntiAlias; ////g.FillRectangle(Brushes.White, this.ClientRectangle); //Pen p = new Pen(Color.Black, 10); //p.StartCap = LineCap.Round; //p.EndCap = LineCap.ArrowAnchor; //g.DrawLine(p, 30, 30, 80, 30); //p.Dispose(); }
private void DrawEdges(object sender, PaintEventArgs e) { Pen myPen = new Pen(Color.Black, 4); Font df = new Font("Times New Roman", 16, FontStyle.Bold); Brush myBrush = new SolidBrush(Color.Black); Brush visitedBrush = new SolidBrush(Color.Red); Pen visitedPen = new Pen(Color.Red, 4); e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.InterpolationMode = InterpolationMode.High; //--Draw Edges--// if (isOriented == 1) { AdjustableArrowCap bigArrow = new AdjustableArrowCap(7, 9); myPen.CustomEndCap = bigArrow; } PointF intersectionPoint; if (temporaryStart != null) { if (temporaryFinish != null && temporaryFinish != temporaryStart) { intersectionPoint = GetIntersection(temporaryStart.GetCenter(), temporaryFinish.GetCenter()); e.Graphics.DrawLine(myPen, temporaryStart.GetCenter(), intersectionPoint); } else { e.Graphics.DrawLine(myPen, temporaryStart.GetCenter(), MouseP); } } for (int i = 1; i <= EdgeNumber; i++) { intersectionPoint = GetIntersection(NodesAdress[Edges[i].Item1].GetCenter(), NodesAdress[Edges[i].Item2].GetCenter()); if (VisitedEdge[i] == 0) { e.Graphics.DrawLine(myPen, NodesAdress[Edges[i].Item1].GetCenter(), intersectionPoint); } else { e.Graphics.DrawLine(visitedPen, NodesAdress[Edges[i].Item1].GetCenter(), intersectionPoint); } int ch1 = 0, ch2 = 0; PointF pf = new PointF(((NodesAdress[Edges[i].Item1].GetCenter().X + intersectionPoint.X) / 2), ((NodesAdress[Edges[i].Item1].GetCenter().Y + intersectionPoint.Y) / 2)); if (isWeighted == 1) { DrawTextOnSegment(e.Graphics, Brushes.Blue, df, Edges[i].Item3.ToString(), ref ch1, ref pf, intersectionPoint, true); } if (isNetwork == 1) { DrawTextOnSegment(e.Graphics, Brushes.Blue, df, Edges[i].Item3.ToString(), ref ch2, ref pf, intersectionPoint, false); } } //--End Draw Edges--// myPen.Dispose(); }
} // OnVelocityChanged private void DrawBoard(Graphics g) { if (null != this.DebugMessage) { g.DrawString(this.DebugMessage, this.Font, Brushes.White, new Point(0, 0)); } // Invert Y axis float scaleX = g.ClipBounds.Width / this.ViewPort.Width; float scaleY = g.ClipBounds.Height / this.ViewPort.Height; float PixelWidth = Math.Max(1 / scaleX, 1 / scaleY); Pen pixelPen = new Pen(Settings.BaseAxiiColor, PixelWidth * 1.5f); Font baseFont = new Font(this.Font.FontFamily, Settings.FontSize * PixelWidth); Font italicFont = new Font(this.Font.FontFamily, Settings.FontSize * PixelWidth, FontStyle.Italic); // Set up transformations g.ScaleTransform(scaleX, -scaleY); g.TranslateTransform(-this.ViewPort.X, -this.ViewPort.Y); if (Settings.ShowGrids) { // Draw basic Grid pixelPen.DashStyle = DashStyle.Solid; pixelPen.Color = Settings.BaseGridColor; float sX, sY; for (double x = Math.Floor(this.ViewPort.X); x < (this.ViewPort.X + this.ViewPort.Width); x += 1f) { sX = Convert.ToSingle(x); g.DrawLine(pixelPen, sX, this.ViewPort.Y, sX, this.ViewPort.Y - this.ViewPort.Height); if (this.m_calc.Velocity != 0) { List <PointF> points = new List <PointF>(); for (double y = Math.Floor(this.ViewPort.Y); y > (this.ViewPort.Y - this.ViewPort.Height); y -= 1f) { sY = Convert.ToSingle(y); points.Add(this.m_calc.TransformPoint(new PointF(sX, sY))); } pixelPen.Color = Settings.RelativisticGridColor; g.DrawCurve(pixelPen, points.ToArray()); } } // for x pixelPen.Color = Settings.BaseGridColor; for (double y = Math.Floor(this.ViewPort.Y); y > (this.ViewPort.Y - this.ViewPort.Height); y -= 1f) { sY = Convert.ToSingle(y); g.DrawLine(pixelPen, this.ViewPort.X, sY, this.ViewPort.X + this.ViewPort.Width, sY); if (this.m_calc.Velocity != 0) { List <PointF> points = new List <PointF>(); for (double x = Math.Floor(this.ViewPort.X); x < (this.ViewPort.X + this.ViewPort.Width); x += 1f) { sX = Convert.ToSingle(x); points.Add(this.m_calc.TransformPoint(new PointF(sX, sY))); } // for x pixelPen.Color = Settings.RelativisticGridColor; g.DrawCurve(pixelPen, points.ToArray()); } } // for y } pixelPen.Color = Settings.BaseAxiiColor; // Arrow cap fox axii AdjustableArrowCap bigArrow = new AdjustableArrowCap(Settings.ArrowCapSize, Settings.ArrowCapSize); pixelPen.SetLineCap(LineCap.Flat, LineCap.ArrowAnchor, DashCap.Flat); pixelPen.CustomEndCap = bigArrow; // Draw a base spatial axis PointF startX = new PointF(this.ViewPort.X, 0f); PointF endX = new PointF(this.ViewPort.X + this.ViewPort.Width, 0f); g.DrawLine(pixelPen, startX, endX); // Draw a base time axis PointF startT = new PointF(0f, this.ViewPort.Y - this.ViewPort.Height); PointF endT = new PointF(0f, this.ViewPort.Y); g.DrawLine(pixelPen, startT, endT); pixelPen.Color = Settings.RelativisticAxiiColor; // Draw a transformed spatial axis startX = this.m_calc.TransformPoint(startX); endX = this.m_calc.TransformPoint(endX); // this.DebugMessage = $"from {startX.X}:{startX.Y} to {endX.X}:{endX.Y}"; float tan = endX.Y / endX.X; endX.X = this.ViewPort.X + this.ViewPort.Width; endX.Y = endX.X * tan; startX.X = this.ViewPort.X; startX.Y = startX.X * tan; g.DrawLine(pixelPen, startX, endX); // Draw a transformed time axis startT = this.m_calc.TransformPoint(startT); endT = this.m_calc.TransformPoint(endT); tan = endT.X / endT.Y; endT.Y = this.ViewPort.Y; endT.X = endT.Y * tan; startT.Y = this.ViewPort.Y - this.ViewPort.Height; startT.X = startT.Y * tan; /*float ratioY = endT.Y / (this.ViewPort.Top); * endT.Y = this.ViewPort.Top; * endT.X = this.ViewPort.X * ratioY;*/ g.DrawLine(pixelPen, startT, endT); pixelPen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Round); pixelPen.Color = Settings.LightConeColor; // Draw light cones float min = Math.Min(this.ViewPort.X, this.ViewPort.Y); float max = Math.Max(this.ViewPort.X + this.ViewPort.Width, this.ViewPort.Y - this.ViewPort.Height); pixelPen.Width = Convert.ToSingle(PixelWidth * 0.5f); g.DrawLine(pixelPen, new PointF(min, min), new PointF(max, max)); g.DrawLine(pixelPen, new PointF(min, -min), new PointF(max, -max)); string axisname = "space"; SizeF labelsize = g.MeasureString(axisname, baseFont); // Pen textPen = new Pen(Color.White, PixelWidth * 1.5f); g.ScaleTransform(1f, -1f); g.DrawString(axisname, italicFont, new SolidBrush(Settings.BaseAxiiColor), this.ViewPort.X + this.ViewPort.Width - labelsize.Width, 0f); axisname = "time (ct)"; g.DrawString(axisname, italicFont, new SolidBrush(Settings.BaseAxiiColor), 0.05f, -this.ViewPort.Y); g.ScaleTransform(1f, -1f); // Draw Original events if (this.m_calc.Velocity != 0) { foreach (SpaceTimeEvent evt in this.m_calc) { Color newColor = Color.FromArgb(128, evt.Color.R, evt.Color.G, evt.Color.B); g.DrawEllipse(new Pen(newColor, PixelWidth), Convert.ToSingle(evt.Position - (Settings.DotSize / 2.0f) * PixelWidth), Convert.ToSingle(evt.Time - (Settings.DotSize / 2.0f) * PixelWidth), Settings.DotSize * PixelWidth, Settings.DotSize * PixelWidth); if (Settings.ShowEventNames) { Brush textColor = new SolidBrush(newColor); g.ScaleTransform(1f, -1f); g.DrawString(evt.Label, baseFont, textColor, Convert.ToSingle(evt.Position + 3 * PixelWidth), Convert.ToSingle(-evt.Time + 3 * PixelWidth)); g.ScaleTransform(1f, -1f); } } // foreach original evetn } // Draw transformed events foreach (SpaceTimeEvent evt in this.m_calc.Select(_event => this.m_calc.Transform(_event))) { g.FillEllipse(new SolidBrush(evt.Color), Convert.ToSingle(evt.Position - (Settings.DotSize / 2.0f) * PixelWidth), Convert.ToSingle(evt.Time - (Settings.DotSize / 2.0f) * PixelWidth), Settings.DotSize * PixelWidth, Settings.DotSize * PixelWidth); if (Settings.ShowEventNames) { Brush textColor = new SolidBrush(evt.Color); g.ScaleTransform(1f, -1f); g.DrawString(evt.Label, baseFont, textColor, Convert.ToSingle(evt.Position + 3 * PixelWidth), Convert.ToSingle(-evt.Time + 3 * PixelWidth)); g.ScaleTransform(1f, -1f); } } // foreach g.ResetTransform(); string mstr = $"v = {this.m_calc.Velocity.ToString("0.00")} c"; Font labelFont = new Font("Times New Roman", 12, FontStyle.Italic); SizeF labelSize = g.MeasureString(mstr, labelFont, this.picDisplay.ClientRectangle.Width); g.DrawString(mstr, labelFont, new SolidBrush(Color.White), Convert.ToSingle(this.picDisplay.ClientRectangle.Width * 0.75 - labelSize.Width / 2), 0.0f); } // Draw
private bool DFS2(int vertexFrom, int vertexTo) { visited = new int[vertex]; path = new int[vertex]; for (int i = 0; i < vertex; i++) { visited[i] = 0; path[i] = -1; } Stack stack = new Stack(); stack.Push(vertexFrom); while (stack.Count != 0) { int element = Convert.ToInt32(stack.Pop()); visited[element] = 1; for (int i = 0; i < vertex; i++) { if (visited[i] == 0 && matrix[element, i] != 0) { visited[i] = 1; stack.Push(i); path[i] = element; } } } int[] result = new int[vertex]; int n = 0; if (visited[vertexTo] == 1) { int j = vertexTo; while (j != vertexFrom) { result[n] = j; j = path[j]; n++; } result[n] = vertexFrom; for (int i = 0; i < n; i++) { //----------------- Pen redPen = new Pen(Color.Red, 2); if (!isSymmetryMatrix()) { AdjustableArrowCap arrowSize = new AdjustableArrowCap(5, 5); redPen.StartCap = LineCap.ArrowAnchor; redPen.CustomStartCap = arrowSize; } g.DrawLine(redPen, point[result[i]], point[result[i + 1]]); redPen.Dispose(); txbPath.Text += (result[i] + 1).ToString() + "<--"; Thread.Sleep(1000); } txbPath.Text += result[n] + 1; MessageBox.Show("Xong", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Không có đường đi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); }
private void Draw() { Response.ContentType = "image/jpeg"; Response.Clear(); int ReportDataID = Convert.ToInt32(Session["RPID"]); //int ReportDataID = 9; //从数据库中取出数据 string str = "select DataSerial from [ReportData] where ReportDataID=@ReportDataID"; string strconn = ConfigurationManager.ConnectionStrings["check"].ConnectionString; SqlConnection conn = new SqlConnection(strconn); conn.Open(); SqlCommand cmd = new SqlCommand(str, conn); cmd.Parameters.Add(new SqlParameter("@ReportDataID", ReportDataID)); string GetLuBoData = cmd.ExecuteScalar().ToString(); int num = GetLuBoData.Length; int[] arr = new int[num]; int c = 0; for (int i = 0; i <= num - 2; i = i + 2) { int rLuBoData = Convert.ToInt32(GetLuBoData.Substring(i, 2), 16); //放到数组中 arr[c] = rLuBoData; c++; } Bitmap img = new Bitmap(num + 30, 200);//创建Bitmap对象 for (int i = 0; i < num + 30; i++) { for (int j = 0; j < 200; j++) { img.SetPixel(i, j, Color.Transparent); } } Graphics g = Graphics.FromImage(img); //创建Graphics对象 g.Clear(Color.White); //清空背景色 Pen Bp = new Pen(Color.Black); //定义画笔 Pen Rp = new Pen(Color.Red); //红色画笔 String[] n = { "200", "150", "100", " 50", " 0" }; Font font = new Font("Arial", 10, FontStyle.Bold); int y = 50; for (int i = 0; i < 5; i++) { g.DrawString(n[i].ToString(), font, Brushes.Red, -3, y); //设置文字内容及输出位置 y = y + 30; } AdjustableArrowCap aac; //定义箭头帽 aac = new AdjustableArrowCap(4, 4); Rp.CustomStartCap = aac; //开始端箭头帽 g.DrawLine(Rp, 20, 20, 20, 180); //纵坐标 g.DrawLine(Rp, num + 32, 180, 20, 180); //横坐标 for (int i = 0; i < num / 2; i++) { g.DrawLine(Bp, 20 + i * (2 + 1 / 2), 180 - arr[i], 20 + (i + 1) * (2 + 1 / 2), 180 - arr[i + 1]); } img.Save(Response.OutputStream, ImageFormat.Jpeg); //释放掉Graphics对象和位图所使用的内存空间 g.Dispose(); img.Dispose(); //把输出结果发送到客户端 //Response.Flush(); }
//Вывод чертежа на экран public void Draw(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; //Перо для рисования осей со стрелкой на конце Pen axisPen = new Pen(bgClr, 1); AdjustableArrowCap cap = new AdjustableArrowCap(4, 4); cap.MiddleInset = 3; axisPen.CustomEndCap = cap; //Перо для рисования осей Pen osiPen = new Pen(bgClr, 1); osiPen.CustomEndCap = new System.Drawing.Drawing2D.AdjustableArrowCap(3.0f, 6.0f); //Перо для рисования окружностей Pen drawellipsePen = new Pen(Color.Black, 1); //Перо для заливки окружностей Pen fillellipsePen = new Pen(Color.Black, 1); //Инструменты для рисования SolidBrush brush = new SolidBrush(bgClr); SolidBrush brushT = new SolidBrush(ptClr); SolidBrush brushTochekT1T2T3 = new SolidBrush(Color.Cyan); SolidBrush brushTochkiT = new SolidBrush(Color.Red); SolidBrush brushTochek = new SolidBrush(Color.Black); Font font = new Font("Arial", 10, FontStyle.Regular); Pen pen = new Pen(ptClr, 1); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; //смещение для надписей int offset = 5; string errorMsg = ""; if (CheckErrors(ref errorMsg)) { g.DrawString(errorMsg, font, brush, 10, height / 2); return; } //Отрисовка координатной системы g.DrawLine(osiPen, O, X); g.DrawLine(osiPen, O, Y); g.DrawLine(osiPen, O, Z); g.DrawString("O", font, brush, O); g.DrawString("X", font, brush, X); g.DrawString("Y", font, brush, Y); g.DrawString("Z", font, brush, Z); //Отрисовка линий связи g.DrawLine(pen, Tx, T1); g.DrawLine(pen, Ty, T1); g.DrawLine(pen, Tx, T2); g.DrawLine(pen, Tz, T2); g.DrawLine(pen, Tz, T3); g.DrawLine(pen, Ty, T3); g.DrawLine(pen, T1, T); g.DrawLine(pen, T2, T); g.DrawLine(pen, T3, T); //Отрисовка точек g.FillEllipse(brushTochek, O.X - radius, O.Y - radius, 2 * radius, 2 * radius); g.DrawEllipse(drawellipsePen, O.X - radius, O.Y - radius, 2 * radius, 2 * radius); g.FillEllipse(brushTochek, Tx.X - radius, Tx.Y - radius, 2 * radius, 2 * radius); g.DrawEllipse(drawellipsePen, Tx.X - radius, Tx.Y - radius, 2 * radius, 2 * radius); g.FillEllipse(brushTochek, Ty.X - radius, Ty.Y - radius, 2 * radius, 2 * radius); g.DrawEllipse(drawellipsePen, Ty.X - radius, Ty.Y - radius, 2 * radius, 2 * radius); g.FillEllipse(brushTochek, Tz.X - radius, Tz.Y - radius, 2 * radius, 2 * radius); g.DrawEllipse(drawellipsePen, Tz.X - radius, Tz.Y - radius, 2 * radius, 2 * radius); g.FillEllipse(brushTochekT1T2T3, T1.X - radius, T1.Y - radius, 2 * radius, 2 * radius); g.DrawEllipse(drawellipsePen, T1.X - radius, T1.Y - radius, 2 * radius, 2 * radius); g.FillEllipse(brushTochekT1T2T3, T2.X - radius, T2.Y - radius, 2 * radius, 2 * radius); g.DrawEllipse(drawellipsePen, T2.X - radius, T2.Y - radius, 2 * radius, 2 * radius); g.FillEllipse(brushTochekT1T2T3, T3.X - radius, T3.Y - radius, 2 * radius, 2 * radius); g.DrawEllipse(drawellipsePen, T3.X - radius, T3.Y - radius, 2 * radius, 2 * radius); g.FillEllipse(brushTochkiT, T.X - radius, T.Y - radius, 2 * radius, 2 * radius); g.DrawEllipse(drawellipsePen, T.X - radius, T.Y - radius, 2 * radius, 2 * radius); //Отрисовка подписей к точкам g.DrawString("Tx", font, brush, Tx.X - offset, Tx.Y + offset); g.DrawString("Ty", font, brush, Ty.X - offset, Ty.Y + offset); g.DrawString("Tz", font, brush, Tz.X + offset, Tz.Y - (offset * 2)); g.DrawString("T1", font, brush, T1.X - offset, T1.Y + offset); g.DrawString("T2", font, brush, T2.X + offset, T2.Y + offset); g.DrawString("T3", font, brush, T3.X + offset, T3.Y + offset); g.DrawString("T", font, brush, T.X + offset, T.Y + offset); }
/// <summary> /// Dessiner l'automate dans un Panel. /// </summary> /// <param name="DrawPanel">Le panel ou on va dessiner l'automate</param> /// <param name="fix">La methode de deplacement des etats dans le dessin /// true pour des emplacements fixes</param> public void Draw(System.Windows.Forms.Panel DrawPanel, bool fix) { Random Ran = new Random(); Dessin = DrawPanel.CreateGraphics(); AutoImage = new Bitmap(DrawPanel.Width, DrawPanel.Height); grImage = Graphics.FromImage(AutoImage); SolidBrush pinceau = new SolidBrush(Color.Blue); Pen myPen = new Pen(Color.Blue, 2); Font myfont = new Font("Verdana", 8, FontStyle.Bold); DrawPanel.Refresh(); //Dessin.PixelOffsetMode = PixelOffsetMode.HighQuality; Dessin.SmoothingMode = SmoothingMode.AntiAlias; grImage.SmoothingMode = SmoothingMode.AntiAlias; Pen inipen = new Pen(Color.Coral, 5); inipen.CustomEndCap = new AdjustableArrowCap(3, 3, false); if (!DessinChanged) if (fix) { myPointArray = new Point[10]; int[] TabX = new int[8]; for (int i = 0; i < 8; i++) { TabX[i] = (int)i * ((DrawPanel.Width - 40) / 7); } int[] TabY = new int[5]; for (int i = 0; i < 5; i++) { TabY[i] = (int)i * ((DrawPanel.Height - 28) / 4); } #region myPointArray myPointArray[0] = new Point(TabX[4], TabY[0]); myPointArray[1] = new Point(TabX[0], TabY[2]); myPointArray[2] = new Point(TabX[7], TabY[2]); myPointArray[3] = new Point(TabX[5], TabY[3]); myPointArray[4] = new Point(TabX[5], TabY[1]); myPointArray[5] = new Point(TabX[2], TabY[3]); myPointArray[6] = new Point(TabX[3], TabY[0]); myPointArray[7] = new Point(TabX[4], TabY[4]); myPointArray[8] = new Point(TabX[2], TabY[1]); myPointArray[9] = new Point(TabX[3], TabY[4]); #endregion } else { myPointArray = new Point[this.S]; //les restes sont calculés double alpha = (Math.PI * 2) / this.S; for (int i = 0; i < this.S; i++) { myPointArray[i] = new Point((int)((Math.Cos((i - 1) * alpha) * (DrawPanel.Width / 2.75)) + DrawPanel.Width / 2.2), (int)((Math.Sin((i - 1) * alpha) * 90) + 100)); } } if (this.S > 10) DrawPanel.BackColor = Color.Red; for (int i = 0; (i < this.S); i++) { Point p = myPointArray[i]; Dessin.DrawEllipse(myPen, p.X, p.Y, 30, 30); grImage.DrawEllipse(myPen, p.X, p.Y, 30, 30); if (this.S0 == i) //etat ititial { Dessin.DrawLine(inipen, p.X - 40, p.Y + 5, p.X - 10, p.Y + 10); grImage.DrawLine(inipen, p.X - 40, p.Y + 5, p.X - 10, p.Y + 10); } if (this.F.Contains(i)) //etat final { grImage.DrawEllipse(myPen, p.X + 2, p.Y + 2, 30 - 4, 30 - 4); Dessin.DrawEllipse(myPen, p.X + 2, p.Y + 2, 30 - 4, 30 - 4); } for (int j = 0; (j < this.S) & (j < 10); j++) { String CsTran = ""; if (this.getType() != TYPE.Gfa) foreach (char car in this.X) { if (this.getType() == TYPE.Dfa) { if (((Dfa)this).getInstruction(i, car) == j) { CsTran += ((CsTran.Length == 0) ? (car.ToString()) : ("/" + car.ToString())); } } else { if (((Automata)this).getInstruction(i, car).Contains(j)) { CsTran += ((CsTran.Length == 0) ? (car.ToString()) : ("/" + car.ToString())); } } } else foreach (Object MotObj in ((Gfa)this).Read) { string Mot = MotObj.ToString(); if (((Gfa)this).getInstruction(i, Mot).Contains(j)) { CsTran += ((CsTran.Length == 0) ? (Mot.ToString()) : ("/" + Mot)); } } #region //DrawTransition(i, j, CsTran); AdjustableArrowCap Fleche = new AdjustableArrowCap(5, 5, true); Pen FlechePen = new Pen(Color.Red, 2); FlechePen.CustomEndCap = Fleche; if (CsTran.Length != 0) // il existe une transition de Si vers Sj { Point p1 = myPointArray[i]; Point p2 = myPointArray[j]; Point t1 = new Point(); Point t2 = new Point(); Point t3 = new Point(); Point t4 = new Point(); /*if (p2.X < p1.X) { t2.X = p1.X; t1.X = p2.X + 30; t3.X = t4.X = ((t1.X + t2.X) / 2) - (20 * i); } else { t2.X = p1.X + 30; t1.X = p2.X; t3.X = t4.X = ((t1.X + t2.X) / 2) + (20 * i); } if (p2.Y < p1.Y) { t2.Y = p1.Y + 15; t1.Y = p2.Y + 15; t3.Y = t4.Y = ((t1.Y + t2.Y) / 2) - (20 * i); } else { t2.Y = p1.Y + 15; t1.Y = p2.Y + 15; t3.Y = t4.Y = ((t1.Y + t2.Y) / 2) + (20 * i); } Dessin.DrawBezier(FlechePen,t1,t3 ,t4,t2); */ if (p2 != p1) { Dessin.DrawBezier(FlechePen, p1.X + ((p1.X > p2.X) ? (0) : (30)), p1.Y + 10 + (2 * i), ((p2.X + p1.X) / 2), ((6 * p1.Y + p2.Y) / 7) - 40 + Ran.Next(80), (p2.X + p1.X) / 2, ((6 * p1.Y + p2.Y) / 7) - 40 + Ran.Next(80), p2.X + ((p1.X > p2.X) ? (30) : (0)), p2.Y + 10 + +(2 * i)); Dessin.DrawString(CsTran, myfont, pinceau, ((p2.X + p1.X) / 2), (4 * p1.Y + p2.Y) / 5); grImage.DrawBezier(FlechePen, p1.X + ((p1.X > p2.X) ? (0) : (30)), p1.Y + 10 + (2 * i), ((p2.X + p1.X) / 2), ((6 * p1.Y + p2.Y) / 7) - 40 + Ran.Next(80), (p2.X + p1.X) / 2, ((6 * p1.Y + p2.Y) / 7) - 40 + Ran.Next(80), p2.X + ((p1.X > p2.X) ? (30) : (0)), p2.Y + 10 + +(2 * i)); grImage.DrawString(CsTran, myfont, pinceau, ((p2.X + p1.X) / 2), (4 * p1.Y + p2.Y) / 5); } else //Si -> Si { Dessin.DrawBezier(FlechePen, p1.X, p1.Y + 15, p1.X + 2, p1.Y + 60, p1.X + 25, p1.Y + 60, p1.X + 30, p1.Y + 15); Dessin.DrawString(CsTran, myfont, pinceau, p1.X + 15, p1.Y + 30); grImage.DrawBezier(FlechePen, p1.X, p1.Y + 15, p1.X + 2, p1.Y + 60, p1.X + 25, p1.Y + 60, p1.X + 30, p1.Y + 15); grImage.DrawString(CsTran, myfont, pinceau, p1.X + 15, p1.Y + 30); } } SolidBrush Fill = new SolidBrush(Color.White); Dessin.FillEllipse(Fill, p.X + 3, p.Y + 3, 30 - 6, 30 - 6); Dessin.DrawString("S" + i, myfont, pinceau, (p.X + 5), (p.Y + 8)); grImage.FillEllipse(Fill, p.X + 3, p.Y + 3, 30 - 6, 30 - 6); grImage.DrawString("S" + i, myfont, pinceau, (p.X + 5), (p.Y + 8)); #endregion } } //DrawPanel.Refresh(); }
public void Paint() { List<Vector> vectors = new List<Vector>() { new Vector(-200, 50), new Vector(300, 250), new Vector(150, -300), new Vector(150, 150) }; List<double> radi = new List<double>() { 50, 50, 50, 20 }; List<Vector> vectorMs = new List<Vector>(); List<Vector> vectorEs = new List<Vector>(); List<Vector> vectorLs = new List<Vector>(); Pen p = new Pen(Color.Aqua, 1); AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 5); p.CustomEndCap = bigArrow; foreach (var vector in vectors) { int vectorIndex = vectors.IndexOf(vector); int vectorIndex0 = ((vectorIndex - 2) % vectors.Count + vectors.Count) % vectors.Count; int vectorIndex1 = ((vectorIndex - 1) % vectors.Count + vectors.Count) % vectors.Count; int vectorIndex3 = ((vectorIndex + 1) % vectors.Count + vectors.Count) % vectors.Count; int vectorIndex4 = ((vectorIndex + 2) % vectors.Count + vectors.Count) % vectors.Count; Vector vectorM; Vector vectorE; Vector vectorL; p.Color = Color.White; path.DrawVector(vector, p); vectorM = CalculateM2(vector, vectors[vectorIndex1], vectors[vectorIndex3], radi[vectorIndex]); p.Color = Color.Violet; path.DrawVector(vector, vectorM, p); vectorE = CalculateE2(vectors[vectorIndex0], vectors[vectorIndex1], vector, vectors[vectorIndex3], vectors[vectorIndex4], radi[vectorIndex1], radi[vectorIndex], radi[vectorIndex3]); vectorL = CalculateL2(vectors[vectorIndex0], vectors[vectorIndex1], vector, vectors[vectorIndex3], vectors[vectorIndex4], radi[vectorIndex1], radi[vectorIndex], radi[vectorIndex3]); p.Color = Color.Green; path.DrawVector(vector + vectorM, vectorE, p); p.Color = Color.Red; path.DrawVector(vector + vectorM, vectorL, p); vectorMs.Add(vector + vectorM); vectorEs.Add(vector + vectorM + vectorE); vectorLs.Add(vector + vectorM + vectorL); } for (int vectorIndex = 0; vectorIndex < vectors.Count; vectorIndex++) { p.Color = Color.Violet; path.DrawCircle(vectorMs[vectorIndex], radi[vectorIndex], p); } for (int vectorIndex = 0; vectorIndex < vectors.Count; vectorIndex++) { int nextVectorIndex = (vectorIndex + 1) % vectors.Count; p.Color = Color.Blue; path.DrawVector(vectorLs[vectorIndex], vectorEs[nextVectorIndex] - vectorLs[vectorIndex], p); } //vectorM1 = CalculateM2(vectorT1, vectorT2, vectorT3, r1); //vectorM2 = CalculateM2(vectorT2, vectorT3, vectorT1, r2); //vectorM3 = CalculateM2(vectorT3, vectorT1, vectorT2, r3); //vectorM1M2 = (vectorT2 + vectorM2) - (vectorT1 + vectorM1); //vectorM2M3 = (vectorT3 + vectorM3) - (vectorT2 + vectorM2); //vectorM3M1 = (vectorT1 + vectorM1) - (vectorT3 + vectorM3); //vectorE1 = CalculateE2(vectorT2, vectorT3, vectorT1, vectorT2, vectorT3, r3, r1, r2); //vectorL1 = CalculateL2(vectorT2, vectorT3, vectorT1, vectorT2, vectorT3, r3, r1, r2); //vectorE2 = CalculateE2(vectorT3, vectorT1, vectorT2, vectorT3, vectorT1, r1, r2, r3); //vectorL2 = CalculateL2(vectorT3, vectorT1, vectorT2, vectorT3, vectorT1, r1, r2, r3); //vectorE3 = CalculateE2(vectorT1, vectorT2, vectorT3, vectorT1, vectorT2, r2, r3, r1); //vectorL3 = CalculateL2(vectorT1, vectorT2, vectorT3, vectorT1, vectorT2, r2, r3, r1); //p.Color = Color.Violet; ////path.DrawVector(vectorT1, vectorM1, p); ////path.DrawVector(vectorT2, vectorM2, p); ////path.DrawVector(vectorT3, vectorM3, p); //path.DrawVector(vectorT1 + vectorM1, vectorM1M2, p); //path.DrawVector(vectorT2 + vectorM2, vectorM2M3, p); //path.DrawVector(vectorT3 + vectorM3, vectorM3M1, p); //path.DrawCircle(vectorT1 + vectorM1, r1, p); //path.DrawCircle(vectorT2 + vectorM2, r2, p); //path.DrawCircle(vectorT3 + vectorM3, r3, p); //p.Color = Color.Green; //path.DrawVector(vectorT1 + vectorM1, vectorE1, p); //path.DrawVector(vectorT2 + vectorM2, vectorE2, p); //path.DrawVector(vectorT3 + vectorM3, vectorE3, p); //p.Color = Color.Red; //path.DrawVector(vectorT1 + vectorM1, vectorL1, p); //path.DrawVector(vectorT2 + vectorM2, vectorL2, p); //path.DrawVector(vectorT3 + vectorM3, vectorL3, p); //p.Color = Color.Blue; //path.DrawVector(vectorT1 + vectorM1 + vectorL1, (vectorT2 + vectorM2 + vectorE2) - (vectorT1 + vectorM1 + vectorL1), p); //path.DrawVector(vectorT2 + vectorM2 + vectorL2, (vectorT3 + vectorM3 + vectorE3) - (vectorT2 + vectorM2 + vectorL2), p); //path.DrawVector(vectorT3 + vectorM3 + vectorL3, (vectorT1 + vectorM1 + vectorE1) - (vectorT3 + vectorM3 + vectorL3), p); }
private void DrawArrow(Color color, int rx, int ry) { Rectangle R = new Rectangle(rx + 8, ry + 8, 16, 16); G.SmoothingMode = SmoothingMode.AntiAlias; Pen P = new Pen(color, 1); AdjustableArrowCap C = new AdjustableArrowCap(3, 2); P.CustomEndCap = C; G.DrawArc(P, R, 0f, 290f); P.Dispose(); C.Dispose(); G.SmoothingMode = SmoothingMode.None; }
private void Redraw_Panel1(Map map)//重绘界面函数 { this.draw_map1.Refresh(); Image route_start = Image.FromFile("../../ico/gps_map_128px_548366_easyicon.net.ico"); Image route_end = Image.FromFile("../../ico/gps_map_128px_548391_easyicon.net.ico"); Image route_point_com = Image.FromFile("../../ico/gps_map_128px_548373_easyicon.net.ico"); Image route_point_urg = Image.FromFile("../../ico/gps_map_128px_548380_easyicon.net.ico"); Graphics g = draw_map1.CreateGraphics(); double p_left = 0, p_right = 0, p_top = 0, p_buttom = 0; //MAP四个角落值 for (int i = 0; i < map.listPoint.Count(); i++) //计算MAP四个角落值 { if (i == 0) { p_left = map.listPoint[i].x; p_right = map.listPoint[i].x; p_top = map.listPoint[i].y; p_buttom = map.listPoint[i].y; } else { if (p_left > map.listPoint[i].x) { p_left = map.listPoint[i].x; } if (p_right < map.listPoint[i].x) { p_right = map.listPoint[i].x; } if (p_top > map.listPoint[i].y) { p_top = map.listPoint[i].y; } if (p_buttom < map.listPoint[i].y) { p_buttom = map.listPoint[i].y; } } } if ((p_buttom - p_top) / draw_map1.Size.Height > (p_right - p_left) / draw_map1.Size.Width) { size_rate = (p_buttom - p_top) / draw_map1.Size.Height * 100 / (size_bar1.Value * 8); } else { size_rate = (p_right - p_left) / draw_map1.Size.Width * 100 / (size_bar1.Value * 8); } int size_rate_r = (int)(1 / size_rate); if (map.listPoint.Count() <= 1) { return; } for (int i = 0; i < draw_map1.Width; i++) { if (i % size_rate_r == 0) { Pen m_pen = new Pen(Brushes.Gray, 3); m_pen.Width = 1; g.DrawLine(m_pen, i, 0, i, draw_map1.Height); } } for (int i = 0; i < draw_map1.Height; i++) { if (i % size_rate_r == 0) { Pen m_pen = new Pen(Brushes.Gray, 3); m_pen.Width = 1; g.DrawLine(m_pen, 0, i, draw_map1.Width, i); } } for (int i = 0; i < map.listLine.Count(); i++) { if (i == select_line) { Pen m_pen = new Pen(Brushes.Red, 3); m_pen.Width = 5; AdjustableArrowCap lineCap = new AdjustableArrowCap(4, 6, true); //带方向箭头 m_pen.CustomEndCap = lineCap; g.DrawLine(m_pen, (float)((map.listLine[i].startpoint.x - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2), (float)(draw_map1.Size.Height - ((map.listLine[i].startpoint.y - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2)), (float)((map.listLine[i].endpoint.x - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2), (float)(draw_map1.Size.Height - ((map.listLine[i].endpoint.y - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2))); } else { Pen m_pen = new Pen(Brushes.DeepSkyBlue, 3); m_pen.Width = 3; AdjustableArrowCap lineCap = new AdjustableArrowCap(4, 6, true); //带方向箭头 m_pen.CustomEndCap = lineCap; g.DrawLine(m_pen, (float)((map.listLine[i].startpoint.x - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2), (float)(draw_map1.Size.Height - ((map.listLine[i].startpoint.y - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2)), (float)((map.listLine[i].endpoint.x - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2), (float)(draw_map1.Size.Height - ((map.listLine[i].endpoint.y - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2))); } if (map.listLine[i].num > 0 && map.listLine[i].num < 31) { string str = "../../ico/id/" + map.listLine[i].num.ToString() + ".bmp"; Image img_num = Image.FromFile(str); g.DrawImage(img_num, (float)(((map.listLine[i].startpoint.x + map.listLine[i].endpoint.x) / 2 - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2) - 15, (float)(draw_map1.Size.Height - (((map.listLine[i].startpoint.y + map.listLine[i].endpoint.y) / 2 - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2)) - 15, 30, 30); } } for (int i = 0; i < map.listPoint.Count(); i++) { if (i == select_point) { g.DrawImage(route_start, (float)((map.listPoint[i].x - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2) - 20, (float)(draw_map1.Size.Height - ((map.listPoint[i].y - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2)) - 38, 40, 40); } else if (map.listPoint[i].type == 0) { if (map.listPoint[i].direc == false) { g.DrawImage(route_point_com, (float)((map.listPoint[i].x - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2) - 15, (float)(draw_map1.Size.Height - ((map.listPoint[i].y - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2)) - 29, 30, 30); } else { g.DrawImage(route_point_urg, (float)((map.listPoint[i].x - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2) - 15, (float)(draw_map1.Size.Height - ((map.listPoint[i].y - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2)) - 29, 30, 30); } } else { g.DrawImage(route_start, (float)((map.listPoint[i].x - (p_right + p_left) / 2) / size_rate + draw_map1.Size.Width / 2) - 15, (float)(draw_map1.Size.Height - ((map.listPoint[i].y - (p_buttom + p_top) / 2) / size_rate + draw_map1.Size.Height / 2)) - 29, 30, 30); } } }