private static void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (m_graphControl == null || (m_shapeType == null && m_shape == null)) { return; } if (e.Button == MouseButtons.Right) { CompleteClear(); } if (m_startDraw) { m_startPoint = new PointF(e.X - m_graphControl.AutoScrollPosition.X, e.Y - m_graphControl.AutoScrollPosition.Y); m_startPoint = m_graphControl.UnzoomPoint(m_startPoint); if (m_shape == null) { m_shape = (Shape)Activator.CreateInstance(m_shapeType); } m_shape.Rectangle = new RectangleF(m_startPoint, new Size(0, 0)); m_shape.IsVisible = true; m_graphControl.AddShape(m_shape); } }
public static void DrawShape(Shape shape, GraphControl graphicControl) { if (graphicControl == null || shape == null) { return; } m_shape = shape; m_graphControl = graphicControl; m_graphControl.Cursor = MouseCursors.Cross; m_startDraw = true; m_graphControl.Locked = true; m_shape.IsVisible = false; if (!m_graphControl.Shapes.Contains(shape)) { m_graphControl.AddShape(m_shape); } m_graphControl.MouseDown -= OnMouseDown; m_graphControl.MouseMove -= OnMouseMove; m_graphControl.MouseUp -= OnMouseUp; m_graphControl.MouseDown += OnMouseDown; m_graphControl.MouseMove += OnMouseMove; m_graphControl.MouseUp += OnMouseUp; }
/// <summary> /// 动态流程图 /// </summary> private void NetronLightGraph() { try { this.groupbox_graph.Controls.Clear(); GraphControl graphControl1 = new GraphControl(); graphControl1.Dock = DockStyle.Fill; graphControl1.Enabled = false; graphControl1.ShowGrid = false; graphControl1.BackColor = Color.SteelBlue; graphControl1.Font = new Font("宋体", 10); this.groupbox_graph.Controls.Add(graphControl1); int x = 50;//this is left margin int y = 30; SimpleRectangle srSharpLast = null; for (int i = 0; i < this.radGridView1.Rows.Count; i++) { var stationName = this.radGridView1.Rows[i].Cells[1].Value.ToString(); SimpleRectangle srSharp = graphControl1.AddShape(ShapeTypes.Rectangular, new Point(x, y)) as SimpleRectangle; Graphics graphics = CreateGraphics(); SizeF sizeF = graphics.MeasureString(stationName, new Font("宋体", 10)); srSharp.Text = stationName; srSharp.Height = 50; srSharp.Width = (int)sizeF.Width + (int)sizeF.Width / 2; graphics.Dispose(); srSharp.ShapeColor = Color.LightSteelBlue; if (i % 2 == 0 && i > 1) { graphControl1.AddConnection(srSharpLast.Connectors[2], srSharp.Connectors[1]); } if (i + 1 < this.radGridView1.Rows.Count) { x += srSharp.Width + 80; var stationNameLast = this.radGridView1.Rows[i + 1].Cells[1].Value.ToString(); Graphics graphicsLast = CreateGraphics(); SizeF sizeFLast = graphicsLast.MeasureString(stationNameLast, new Font("宋体", 10)); srSharpLast = graphControl1.AddShape(ShapeTypes.Rectangular, new Point(x, y)) as SimpleRectangle; srSharpLast.Text = stationNameLast; srSharpLast.Height = 50; srSharpLast.Width = (int)sizeFLast.Width + (int)sizeFLast.Width / 2; graphicsLast.Dispose(); srSharpLast.ShapeColor = Color.LightSteelBlue; graphControl1.AddConnection(srSharp.Connectors[2], srSharpLast.Connectors[1]); i++; } if (srSharpLast == null) { return; } x += srSharpLast.Width + 80; } } catch (Exception ex) { LogHelper.Log.Error(ex.Message); } }