예제 #1
0
파일: GraphUI.cs 프로젝트: cobaka/dm8
        protected override void OnMouseDown(MouseEventArgs e)
        {
            //foreach(Control ctl in this.Controls)

            if (e.Button == MouseButtons.Left)
            {
                if (this.Tool == DrawingTools.Node)
                {
                    int m = 'Z' - 'A' + 2;
                    if (this.Controls.Count == m)
                    {
                        MessageBox.Show("You can only add " + m + " nodes to graph");
                        return;
                    }
                    AddNewNode(e.Location);
                }
                else if (this.Tool == DrawingTools.Edge || this.Tool == DrawingTools.Eraser)
                {
                    int count = 0;
                    foreach (var edge in _edges)
                    {
                        var start = this.Controls[edge.Start].Location;
                        start.X += NODE_RADIUS;
                        start.Y += NODE_RADIUS;
                        var end = this.Controls[edge.End].Location;
                        end.X += NODE_RADIUS;
                        end.Y += NODE_RADIUS;
                        if (Edge.Contains(start, end, e.Location))
                        {
                            if (this.Tool == DrawingTools.Edge)
                            {
                                _edges.SelectedIndex = count;
                            }
                            else if (this.Tool == DrawingTools.Eraser)
                            {
                                _edges.RemoveAt(count);
                                _edges.SelectedIndex = -1;
                            }
                            this.Invalidate();

                            break;
                        }
                        count++;
                    }
                }
                else if (this.Tool == DrawingTools.Eraser) // delete edge
                {
                }
            }
            OnContentChanged(null, null);
            base.OnMouseDown(e);
        }