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);
                }
            }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (_readOnly)
            {
                return;
            }
            hideSelectorList();
            int   x       = e.X;
            int   y       = e.Y;
            int   nh      = 1;
            float yOffset = 0;
            float xOffset = this.AutoScrollPosition.X;
            SizeF size    = mathExp.ExpSize;

            if (size.Height > 0)
            {
                while (y > (nh * (size.Height + 8)))
                {
                    yOffset += (size.Height + 8);
                    xOffset -= this.ClientSize.Width;
                    nh++;
                }
                y -= (int)yOffset;
                x -= (int)xOffset;
            }
            MathNode hit = mathExp.HitTest(new PointF(x, y));

            if (hit != null)
            {
                mathExp.SetFocus(hit);
            }
            else
            {
                mathExp.SetFocus(null);
            }
            this.Refresh();
            if (e.Button == MouseButtons.Right)
            {
                MathNode        selectedNode = Root.FocusedNode;
                ContextMenu     cm           = new ContextMenu();
                MenuItem        mi;
                BinOperatorNode bin = selectedNode as BinOperatorNode;
                if (bin != null)
                {
                    BinOperatorNode bin2 = bin[1] as BinOperatorNode;
                    if (bin2 != null)
                    {
                        //modify it from {0} b {b2} to
                        //{0} b {b2[0]} b2 {b2[1]}
                        //new b[1] = {b2[0]}
                        //new b2[0] = new b => {0} b {b2[0]}
                        //new b2[1] = {b2[1]}
                        mi = new MenuItemWithBitmap("Separate", mnu_separate, Resource1._separate.ToBitmap());
                        cm.MenuItems.Add(mi);
                    }
                }
                if (OnFinish != null)
                {
                    if (cm.MenuItems.Count > 0)
                    {
                        cm.MenuItems.Add("-");
                    }
                    mi = new MenuItemWithBitmap("Finish", OnFinish, Resource1._ok.ToBitmap());
                    cm.MenuItems.Add(mi);
                }
                if (OnCancel != null)
                {
                    mi = new MenuItemWithBitmap("Cancel", OnCancel, Resource1._cancel.ToBitmap());
                    cm.MenuItems.Add(mi);
                }
                if (OnCreateCompound != null)
                {
                }
                //
                if (cm.MenuItems.Count > 0)
                {
                    cm.Show(this, new Point(e.X, e.Y));
                }
            }
        }