public static void UpdateGUI() { Program.form1.Invoke(new Action(() => { Graphics formGraphics = Program.form1.panel1.CreateGraphics(); formGraphics.Clear(Color.White); if (GDEXControl.dex.graph.Count > 1) { Pen myPen = new Pen(Color.Black, 2); Pen myPenRed = new Pen(Color.Red, 2); formGraphics.Clear(Color.White); formGraphics.SmoothingMode = SmoothingMode.AntiAlias; for (int i = 0; i < GDEXControl.dex.graph.Count; i++) { for (int e = 0; e < GDEXControl.dex.graph[i].edges.Count; e++) { Point p1 = new Point(GDEXControl.dex.graph[i].button.Location.X + GDEXControl.dex.graph[i].button.Size.Width / 2, GDEXControl.dex.graph[i].button.Location.Y + GDEXControl.dex.graph[i].button.Size.Height / 2); Point p2 = new Point(GDEXControl.dex.graph[i].edges[e].vertex.button.Location.X + GDEXControl.dex.graph[i].edges[e].vertex.button.Size.Width / 2, GDEXControl.dex.graph[i].edges[e].vertex.button.Location.Y + GDEXControl.dex.graph[i].edges[e].vertex.button.Size.Height / 2); formGraphics.DrawLine(myPen, p1, p2); Point textP = new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); SizeF size = formGraphics.MeasureString(GDEXControl.dex.graph[i].edges[e].price.ToString(), new Font("Microsoft Sans Serif", 14)); formGraphics.FillRectangle(Brushes.Black, new Rectangle(textP.X, textP.Y, (int)size.Width, (int)size.Height)); formGraphics.DrawString(GDEXControl.dex.graph[i].edges[e].price.ToString(), new Font("Microsoft Sans Serif", 14), Brushes.Red, textP); } } for (int jojo = 0; jojo < GDEXControl.dex.pathVertexes.Count - 1; jojo++) { Point p1 = new Point(GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo]).button.Location.X + GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo]).button.Size.Width / 2, GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo]).button.Location.Y + GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo]).button.Size.Height / 2); Point p2 = new Point(GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo + 1]).button.Location.X + GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo + 1]).button.Size.Width / 2, GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo + 1]).button.Location.Y + GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo + 1]).button.Size.Height / 2); formGraphics.DrawLine(myPenRed, p1, p2); } for (int jojo = 0; jojo < GDEXControl.dex.pathVertexes.Count; jojo++) { Point textP = new Point(GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo]).button.Location.X + 25, GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo]).button.Location.Y - 25); SizeF size = formGraphics.MeasureString(GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo]).price.ToString(), new Font("Microsoft Sans Serif", 14)); formGraphics.FillRectangle(Brushes.White, new Rectangle(textP.X, textP.Y, (int)size.Width, (int)size.Height)); formGraphics.DrawString(GDEXControl.GetVertex(GDEXControl.dex.pathVertexes[jojo]).price.ToString(), new Font("Microsoft Sans Serif", 14), Brushes.Red, textP); } myPen.Dispose(); formGraphics.Dispose(); } formGraphics.Dispose(); })); }
public static void AddEdge(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { foreach (Dex.Vertex ver in GDEXControl.dex.graph) { if (sender == ver.button) { if (!Temp.Fstart) { Temp.Fstart = true; Temp.ver1 = ver.name; Temp.start = ver.position; } else if (!Temp.Fstop) { if (Temp.ver1 != ver.name) { Temp.Fstop = true; Temp.ver2 = ver.name; Temp.stop = ver.position; } } if (Temp.Fstop && Temp.Fstart) { if (!findPath) { using (dialoge form = new dialoge()) { form.type = "int"; form.maxlen = 9; form.default_rich = ((int)Math.Sqrt(Math.Pow(GDEXControl.GetVertex(Temp.ver2).button.Location.X - GDEXControl.GetVertex(Temp.ver1).button.Location.X, 2) + Math.Pow(GDEXControl.GetVertex(Temp.ver2).button.Location.Y - GDEXControl.GetVertex(Temp.ver1).button.Location.Y, 2)) / 4).ToString(); form.Text = "Введите цену ребра " + Temp.ver1 + " => " + Temp.ver2; DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { int price = 0; if (Int32.TryParse(form.value, out int res)) { price = res; } GDEXControl.addEdge(Temp.ver1, Temp.ver2, price, null); UpdateGUI(); } } } else { GDEXControl.MathGraph(Temp.ver1, Temp.ver2); } GUI.UpdateGUI(); // for windows < 10 Temp = new Edge(); } } } } }