Exemplo n.º 1
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (e.Button == MouseButtons.Right)
            {
                return;
            }

            ToolBoxItem item = GetToolboxItemByPoint(e.Location);

            if (item != null)
            {
                if (!(item is ToolBoxCategory))
                {
                    Console.WriteLine(DateTime.Now.Second.ToString() + ":" + e.Button.ToString());
                    if (e.Button == MouseButtons.Left)
                    {
                        if (null != ItemDragStart)
                        {
                            ItemDragStart(this, item);
                        }
                        return;
                    }

                    _mouseHoverItem = item;
                    Invalidate();
                }
                else
                {
                    _mouseHoverItem = null;
                    Invalidate();
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            ToolBoxItem item = GetToolboxItemByPoint(e.Location);

            if (item != null)
            {
                if (item is ToolBoxCategory)
                {
                    ToolBoxCategory tbc = item as ToolBoxCategory;
                    tbc.IsOpen = !tbc.IsOpen;
                    RefreshScrollBar();
                    Invalidate();
                }
                else
                {
                    _selectedItem = item;

                    if (null != SelectedItemChanged)
                    {
                        SelectedItemChanged(this, _selectedItem);
                    }
                    if (2 == e.Clicks && null != ItemDoubleClicked)
                    {
                        ItemDoubleClicked(this, _selectedItem);
                    }

                    Invalidate();
                }
            }
            Focus();
        }
Exemplo n.º 3
0
        private ToolBoxItem GetToolboxItemByPoint(Point pi)
        {
            ToolBoxItem result = null;
            Int32       top    = _itemSpace;

            if (vScrollBar1.Visible)
            {
                top -= vScrollBar1.Value;
            }

            foreach (ToolBoxCategory tbc in _categories)
            {
                Rectangle rectCategory = new Rectangle(0, top, this.Width, _categoryHeight);
                if (rectCategory.Contains(pi))
                {
                    result = tbc;
                    break;
                }
                else
                {
                    if (tbc.IsOpen)
                    {
                        top += _categoryHeight + _itemSpace;
                        Boolean find = false;
                        foreach (ToolBoxItem tbi in tbc.Items)
                        {
                            Rectangle rectItem = new Rectangle(0, top, this.Width, _itemHeight);
                            if (rectItem.Contains(pi))
                            {
                                tbi.Parent = tbc;
                                result     = tbi;
                                find       = true;
                                break;
                            }
                            else
                            {
                                top += _itemHeight + _itemSpace;
                            }
                        }

                        if (find)
                        {
                            break;
                        }
                    }
                    else
                    {
                        top += _categoryHeight + _itemSpace;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 4
0
 public void ResetSelection()
 {
     _selectedItem = null;
     Invalidate();
 }
Exemplo n.º 5
0
 protected override void OnMouseLeave(EventArgs e)
 {
     base.OnMouseLeave(e);
     _mouseHoverItem = null;
     Invalidate();
 }