private void setLineSelection(LinkLineNode node, bool selected)
 {
     if (node != null)
     {
         if (selected)
         {
             node.SelectLine(selected);
         }
         else
         {
             bool bCanDeSelect = true;
             if (_selectedLine != null)
             {
                 if (_selectedLine.IsOnTheLine(node))
                 {
                     bCanDeSelect = false;
                 }
             }
             if (bCanDeSelect)
             {
                 node.SelectLine(selected);
             }
         }
     }
 }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            LinkLineNode nodeTest = HitTest(e.X, e.Y);

            if (nodeTest != null)
            {
                this.Cursor = Cursors.Hand;
                nodeTest.SelectLine(true);
            }
            else
            {
                this.Cursor = Cursors.Default;
            }
            if (!bMouseIn)
            {
                bMouseIn = true;
                for (int i = 0; i < Controls.Count; i++)
                {
                    ActiveDrawing ad = Controls[i] as ActiveDrawing;
                    if (ad != null)
                    {
                        ad.FireOnLeave(e);
                    }
                }
            }
        }
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            LinkLineNode nodeTest = HitTest(e.X, e.Y);

            if (nodeTest != null)
            {
                nodeTest.SelectLine(true);
                nodeTest.InsertNode(e.X, e.Y);
            }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            LinkLineNode nodeTest = HitTest(e.X, e.Y);

            if (nodeTest != null)
            {
                if (AllowLineSelection)
                {
                    nodeTest.SelectLine(true);
                    if (nodeTest.Start != null && nodeTest.End != null)
                    {
                        LinkLineNodeOutPort startNode = nodeTest.Start as LinkLineNodeOutPort;
                        LinkLineNodeInPort  endNode   = nodeTest.End as LinkLineNodeInPort;
                        if (startNode != null && endNode != null)
                        {
                            bool bChanged = true;
                            if (_selectedLine != null)
                            {
                                if (_selectedLine.StartNode.PortID == startNode.PortID &&
                                    _selectedLine.StartNode.PortInstanceID == startNode.PortInstanceID &&
                                    _selectedLine.EndNode.PortID == endNode.PortID &&
                                    _selectedLine.EndNode.PortInstanceID == endNode.PortInstanceID)
                                {
                                    bChanged = false;
                                }
                            }
                            if (bChanged)
                            {
                                _selectedLine = new LinkLineEnds(startNode, endNode);
                                OnLineSelectionChanged();
                            }
                        }
                    }
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                ContextMenu mnu = new ContextMenu();
                Point       pt  = new Point(e.X, e.Y);
                if (nodeTest != null)
                {
                    //nodeTest is the line holder
                    nodeTest.SelectLine(true);
                    MenuItemWithBitmap mi = new MenuItemWithBitmap("Add line join", Resource1.newLineBreak);
                    mi.Click += new EventHandler(miAddLineNode_Click);
                    mi.Tag    = new NodeData(nodeTest, pt);
                    mnu.MenuItems.Add(mi);
                    //
                    if (AllowLineDisconnect)
                    {
                        if (nodeTest.LinkedInPort != null && nodeTest.LinkedOutPort != null)
                        {
                            mi        = new MenuItemWithBitmap("Disconnect", Resource1.disconnect);
                            mi.Click += new EventHandler(miDisconnectNodes_Click);
                            mi.Tag    = new NodeData(nodeTest, pt);
                            mnu.MenuItems.Add(mi);
                        }
                    }
                    OnCreateContextMenuForLinkLine(nodeTest, mnu, pt);
                }
                else
                {
                    OnCreateContextMenu(mnu, pt);
                }
                if (mnu.MenuItems.Count > 0)
                {
                    _menuPoint = pt;
                    mnu.Show(this, pt);
                }
            }
        }