Example #1
0
        public void Draw(object item, Graphics g, Rectangle boundRect, bool drawSelected)
        {
            if (!IsHandled(item))
            {
                return;
            }

            RichText.RichText text = ((ListItem)myItems[item]).RichText;
            Image             icon = ((ListItem)myItems[item]).Icon;

            Rectangle rect        = CalculateItemRectangle(item, boundRect);
            Rectangle contentRect = CalculateContentRectangle(item, g, rect);

            // Center content vertically
            if (contentRect.Height < rect.Height)
            {
                int topOffset = (rect.Height - contentRect.Height) / 2;
                contentRect.Y += topOffset;
            }

            //object selectedItem = myListBox.SelectedIndex < 0 || myListBox.SelectedIndex >= myListBox.Items.Count
            //  ? null : myListBox.Items[myListBox.SelectedIndex];

            g.FillRectangle(new SolidBrush(myListBox.BackColor), boundRect);

            if (drawSelected)
            {
                Color backgroundColor = Colors.ListSelectionBackColor(myListBox.Focused);

                text = (RichText.RichText)text.Clone();

                g.FillRectangle(new SolidBrush(backgroundColor), rect);
                text.SetColors(SystemColors.HighlightText, backgroundColor);
            }

            if (icon != null)
            {
                DrawIcon(g, icon, boundRect, item);
            }

            IntPtr hdc = g.GetHdc();

            try
            {
                text.Draw(hdc, contentRect);
                //System.Console.WriteLine(text.ToString());
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }

            if (drawSelected && myListBox.Focused)
            {
                DrawDottedRectangle(g, rect);
            }
        }
Example #2
0
        public void Draw(System.Windows.Forms.ListViewItem item, System.Drawing.Graphics g, Rectangle boundRect)
        {
            if (!IsHandled(item))
            {
                return;
            }

            ListView listView = item.ListView;

            RichText.RichText text        = (RichText.RichText)myItems[item];
            Rectangle         rect        = CalculateItemRectangle(item, boundRect);
            Rectangle         contentRect = CalculateContentRectangle(item, g, rect);

            // Center content vertically
            if (contentRect.Height < rect.Height)
            {
                int topOffset = (rect.Height - contentRect.Height) / 2;
                contentRect.Y += topOffset;
            }

            g.FillRectangle(new SolidBrush(listView.BackColor), rect);

            if (item.Selected)
            {
                Color backgroundColor = Colors.ListSelectionBackColor(listView.Focused);

                text = (RichText.RichText)text.Clone();

                g.FillRectangle(new SolidBrush(backgroundColor), rect);
                text.SetColors(SystemColors.HighlightText, backgroundColor);
            }

            g.SetClip(rect);

            IntPtr hdc = g.GetHdc();

            try
            {
                text.Draw(hdc, contentRect);
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }

            if (item.Selected && listView.Focused)
            {
                DrawDottedRectangle(g, rect);
            }
        }
Example #3
0
        public void Draw(TreeNode node, IntPtr hdc, Rectangle rect)
        {
            if (!IsHandled(node) || node.Bounds.IsEmpty || node.IsEditing)
            {
                return;
            }

            CustomTreeView.CustomTreeView treeView = (CustomTreeView.CustomTreeView)node.TreeView;

            int offset = CalculateOffset(node);

            RichText.RichText text = (RichText.RichText)myNodes[node];

            Rectangle contentRect = CalculateContentRectangle(node, hdc, offset);

            rect.X     += offset;
            rect.Width -= offset;

            Rectangle fullRect = new Rectangle(contentRect.X - 1, node.Bounds.Top, contentRect.Width + 5, node.Bounds.Height);

            //g.SetClip(fullRect);

            TreeNode dropHiliteNode = treeView.DraggingOver ? treeView.DropHighlightedNode : null;
            bool     hasFocus       = node.TreeView.Focused;
            bool     drawSelected   = treeView.DraggingOver
          ? (node == dropHiliteNode)
          : node.IsSelected && hasFocus;
            bool drawNonfocusedSelection = node.IsSelected && !node.TreeView.HideSelection &&
                                           (!hasFocus || treeView.DraggingOver);

            Color backColor;

            if (drawSelected)
            {
                backColor = SystemColors.Highlight;
            }
            else if (drawNonfocusedSelection)
            {
                backColor = SystemColors.Control;
            }
            else
            {
                backColor = treeView.BackColor;
            }

            IntPtr hBrush = Win32Declarations.CreateSolidBrush(Win32Declarations.ColorToRGB(backColor));

            RECT lineRect = new RECT(fullRect.Left - 1, node.Bounds.Top, fullRect.Right + 1, node.Bounds.Bottom);

            Win32Declarations.FillRect(hdc, ref lineRect, hBrush);
            Win32Declarations.DeleteObject(hBrush);

            if (drawSelected)
            {
                text = (RichText.RichText)text.Clone();
                text.SetColors(SystemColors.HighlightText, SystemColors.Highlight);
            }
            else if (drawNonfocusedSelection)
            {
                text = (RichText.RichText)text.Clone();
                text.SetColors(SystemColors.WindowText, SystemColors.Control);
            }

            text.Draw(hdc, contentRect);

            if (hasFocus && treeView.SelectedNode == node && treeView.NeedFocusRect() && dropHiliteNode == null)
            {
                RECT rc = new RECT(fullRect.Left - 1, fullRect.Top, fullRect.Right + 1, fullRect.Bottom);
                Win32Declarations.DrawFocusRect(hdc, ref rc);
            }
        }