Exemplo n.º 1
0
        public virtual void DrawSelectionBackground(Graphics dc, Rectangle nodeRect, Node node)
        {
            Point mousePoint = m_owner.PointToClient(Cursor.Position);
            Node  hoverNode  = m_owner.CalcHitNode(mousePoint);

            if (m_owner.NodesSelection.Contains(node) || m_owner.FocusedNode == node)
            {
                Color col = m_owner.Focused ? SystemColors.Highlight : SystemColors.ControlLight;

                if (!Application.RenderWithVisualStyles)
                {
                    // have to fill the solid background only before the node is painted
                    dc.FillRectangle(SystemBrushes.FromSystemColor(col), nodeRect);
                }
                else
                {
                    col = m_owner.Focused ? SystemColors.Highlight : Color.FromArgb(180, SystemColors.ControlDark);

                    // have to draw the transparent background after the node is painted
                    VisualStyleItemBackground.Style style = VisualStyleItemBackground.Style.Normal;
                    if (m_owner.Focused == false)
                    {
                        style = VisualStyleItemBackground.Style.Inactive;
                    }
                    VisualStyleItemBackground rendere = new VisualStyleItemBackground(style);
                    rendere.DrawBackground(m_owner, dc, nodeRect, col);
                }
            }
            else if (hoverNode == node && m_owner.RowOptions.HoverHighlight)
            {
                Color col = SystemColors.ControlLight;

                if (!Application.RenderWithVisualStyles)
                {
                    // have to fill the solid background only before the node is painted
                    dc.FillRectangle(SystemBrushes.FromSystemColor(col), nodeRect);
                }
                else
                {
                    // have to draw the transparent background after the node is painted
                    VisualStyleItemBackground.Style style = VisualStyleItemBackground.Style.Normal;
                    if (m_owner.Focused == false)
                    {
                        style = VisualStyleItemBackground.Style.Inactive;
                    }
                    VisualStyleItemBackground rendere = new VisualStyleItemBackground(style);
                    rendere.DrawBackground(m_owner, dc, nodeRect, col);
                }
            }

            if (m_owner.Focused && (m_owner.FocusedNode == node))
            {
                nodeRect.Height += 1;
                nodeRect.Inflate(-1, -1);
                ControlPaint.DrawFocusRectangle(dc, nodeRect);
            }
        }
        protected override bool GetHitTest(Point point)
        {
            // if mouse is over node, columns or scrollbar then return true
            // which will cause the mouse event to be forwarded to the control
            TreeListView tree = Control as TreeListView;

            point = tree.PointToClient(point);

            Node node = tree.CalcHitNode(point);

            if (node != null)
            {
                return(true);
            }

            TreelistView.HitInfo colinfo = tree.CalcColumnHit(point);
            if ((int)(colinfo.HitType & HitInfo.eHitType.kColumnHeader) > 0)
            {
                return(true);
            }

            if (tree.HitTestScrollbar(point))
            {
                return(true);
            }
            return(base.GetHitTest(point));
        }
Exemplo n.º 3
0
        private void timer_Tick(object sender, EventArgs e)
        {
            // get node at mouse position
            Point            pt   = treeView.PointToClient(MousePosition);
            TreeListViewItem node = this.treeView.GetItemAt(pt);

            if (node == null)
            {
                return;
            }

            // if mouse is near to the top, scroll up
            if (pt.Y < 30)
            {
                // set actual node to the upper one
                if (node.PrevVisibleItem != null)
                {
                    node = node.PrevVisibleItem;

                    // hide drag image
                    ImageList_DragShowNolock(false);
                    // scroll and refresh
                    node.EnsureVisible();
                    this.treeView.Refresh();
                    // show drag image
                    ImageList_DragShowNolock(true);
                }
            }
            // if mouse is near to the bottom, scroll down
            else if (pt.Y > this.treeView.Size.Height - 30)
            {
                if (node.NextVisibleItem != null)
                {
                    node = node.NextVisibleItem;

                    ImageList_DragShowNolock(false);
                    node.EnsureVisible();
                    this.treeView.Refresh();
                    ImageList_DragShowNolock(true);
                }
            }
        }