Ejemplo n.º 1
0
        private void DoTreeCustomDrawing(ref Message m)
        {
            NMTVCUSTOMDRAW tvcd  = (NMTVCUSTOMDRAW)m.GetLParam(typeof(NMTVCUSTOMDRAW));
            IntPtr         hNode = (IntPtr)tvcd.nmcd.dwItemSpec;
            Rectangle      rect  = GetItemRect(hNode);

            // Create a graphic object from the Device context in the message
            Graphics g = Graphics.FromHdc(tvcd.nmcd.hdc);

            // If this item has the focus draw the higlighting rectangle
            if (itemHasFocus)
            {
                using (Brush brush = new SolidBrush(ColorUtil.VSNetSelectionColor))
                {
                    g.FillRectangle(brush, rect.Left, rect.Top, rect.Width - 1, rect.Height - 1);
                    g.DrawRectangle(SystemPens.Highlight, rect.Left, rect.Top, rect.Width - 1, rect.Height - 1);
                }
            }

            // Draw Text
            string itemText = GetItemText(hNode);
            Size   textSize = TextUtil.GetTextSize(g, itemText, Font);
            Point  pos      = new Point(rect.Left, rect.Top + (rect.Height - textSize.Height) / 2);

            g.DrawString(itemText, Font, SystemBrushes.ControlText, pos);

            // Put structure back in the message
            Marshal.StructureToPtr(tvcd, m.LParam, true);
            m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_SKIPDEFAULT;
        }
Ejemplo n.º 2
0
        private bool NotifyTreeCustomDraw(ref Message m)
        {
            m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_DODEFAULT;
            NMTVCUSTOMDRAW tvcd       = (NMTVCUSTOMDRAW)m.GetLParam(typeof(NMTVCUSTOMDRAW));
            IntPtr         thisHandle = Handle;

            if (tvcd.nmcd.hdr.hwndFrom != Handle)
            {
                return(false);
            }
            switch (tvcd.nmcd.dwDrawStage)
            {
            case (int)CustomDrawDrawStateFlags.CDDS_PREPAINT:
                // Ask for Item painting notifications
                m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_NOTIFYITEMDRAW;
                break;

            case (int)CustomDrawDrawStateFlags.CDDS_ITEMPREPAINT:

                itemHasFocus = false;
                if ((tvcd.nmcd.uItemState & (int)CustomDrawItemStateFlags.CDIS_FOCUS) != 0)
                {
                    itemHasFocus = true;
                }

                // Set the text and background text color to the window bakcground
                // text so that we don't see the text being painted
                tvcd.clrText = ColorUtil.RGB(SystemColors.Window.R,
                                             SystemColors.Window.G, SystemColors.Window.B);
                tvcd.clrTextBk = ColorUtil.RGB(SystemColors.Window.R,
                                               SystemColors.Window.G, SystemColors.Window.B);

                // Put structure back in the message
                Marshal.StructureToPtr(tvcd, m.LParam, true);
                m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_NOTIFYPOSTPAINT;
                break;

            case (int)CustomDrawDrawStateFlags.CDDS_ITEMPOSTPAINT:
                DoTreeCustomDrawing(ref m);
                break;

            default:
                break;
            }
            return(false);
        }