private void DrawTreeItem(string itemText, int imageIndex, IntPtr dc, System.Windows.Forms.NativeMethods.RECT rcIn, int state, int backColor, int textColor) { IntNativeMethods.SIZE size = new IntNativeMethods.SIZE(); IntNativeMethods.RECT lpRect = new IntNativeMethods.RECT(); IntNativeMethods.RECT rect = new IntNativeMethods.RECT(rcIn.left, rcIn.top, rcIn.right, rcIn.bottom); ImageList imageList = base.ImageList; IntPtr zero = IntPtr.Zero; if ((state & 2) != 0) { zero = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(base.Parent, base.Parent.FontHandle)); } if (((state & 1) != 0) && (this.hbrushDither != IntPtr.Zero)) { this.FillRectDither(dc, rcIn); System.Windows.Forms.SafeNativeMethods.SetBkMode(new HandleRef(null, dc), 1); } else { System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), backColor); IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 6, ref rect, null, 0, null); } IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(null, dc), itemText, size); lpRect.left = (rect.left + 0x10) + 8; lpRect.top = rect.top + (((rect.bottom - rect.top) - size.cy) >> 1); lpRect.bottom = lpRect.top + size.cy; lpRect.right = rect.right; System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(null, dc), textColor); IntUnsafeNativeMethods.DrawText(new HandleRef(null, dc), itemText, ref lpRect, 0x8804); System.Windows.Forms.SafeNativeMethods.ImageList_Draw(new HandleRef(imageList, imageList.Handle), imageIndex, new HandleRef(null, dc), 4, rect.top + (((rect.bottom - rect.top) - 0x10) >> 1), 1); if ((state & 2) != 0) { int clr = System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlLightLight)); lpRect.left = rect.left; lpRect.top = rect.top; lpRect.bottom = rect.top + 1; lpRect.right = rect.right; IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null); lpRect.bottom = rect.bottom; lpRect.right = rect.left + 1; IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null); System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlDark)); lpRect.left = rect.left; lpRect.right = rect.right; lpRect.top = rect.bottom - 1; lpRect.bottom = rect.bottom; IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null); lpRect.left = rect.right - 1; lpRect.top = rect.top; IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null); System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), clr); } if (zero != IntPtr.Zero) { System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(null, zero)); } }
private void DrawTreeItem(string itemText, int imageIndex, IntPtr dc, NativeMethods.RECT rcIn, int state, int backColor, int textColor) { IntNativeMethods.SIZE size = new IntNativeMethods.SIZE(); IntNativeMethods.RECT rc2 = new IntNativeMethods.RECT(); IntNativeMethods.RECT rc = new IntNativeMethods.RECT(rcIn.left, rcIn.top, rcIn.right, rcIn.bottom); ImageList imagelist = this.ImageList; IntPtr hfontOld = IntPtr.Zero; // Select the font of the dialog, so we don't get the underlined font // when the item is being tracked if ((state & STATE_HOT) != 0) { hfontOld = SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(Parent, ((Control)Parent).FontHandle)); } // Fill the background if (((state & STATE_SELECTED) != 0) && (hbrushDither != IntPtr.Zero)) { FillRectDither(dc, rcIn); SafeNativeMethods.SetBkMode(new HandleRef(null, dc), NativeMethods.TRANSPARENT); } else { SafeNativeMethods.SetBkColor(new HandleRef(null, dc), backColor); IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_CLIPPED | NativeMethods.ETO_OPAQUE, ref rc, null, 0, null); } // Get the height of the font IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(null, dc), itemText, size); // Draw the caption rc2.left = rc.left + SIZE_ICON_X + 2 * PADDING_HORZ; rc2.top = rc.top + (((rc.bottom - rc.top) - size.cy) >> 1); rc2.bottom = rc2.top + size.cy; rc2.right = rc.right; SafeNativeMethods.SetTextColor(new HandleRef(null, dc), textColor); IntUnsafeNativeMethods.DrawText(new HandleRef(null, dc), itemText, ref rc2, IntNativeMethods.DT_LEFT | IntNativeMethods.DT_VCENTER | IntNativeMethods.DT_END_ELLIPSIS | IntNativeMethods.DT_NOPREFIX); SafeNativeMethods.ImageList_Draw(new HandleRef(imagelist, imagelist.Handle), imageIndex, new HandleRef(null, dc), PADDING_HORZ, rc.top + (((rc.bottom - rc.top) - SIZE_ICON_Y) >> 1), NativeMethods.ILD_TRANSPARENT); // Draw the hot-tracking border if needed if ((state & STATE_HOT) != 0) { int savedColor; // top left savedColor = SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlLightLight)); rc2.left = rc.left; rc2.top = rc.top; rc2.bottom = rc.top + 1; rc2.right = rc.right; IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null); rc2.bottom = rc.bottom; rc2.right = rc.left + 1; IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null); // bottom right SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlDark)); rc2.left = rc.left; rc2.right = rc.right; rc2.top = rc.bottom - 1; rc2.bottom = rc.bottom; IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null); rc2.left = rc.right - 1; rc2.top = rc.top; IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null); SafeNativeMethods.SetBkColor(new HandleRef(null, dc), savedColor); } if (hfontOld != IntPtr.Zero) { SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(null, hfontOld)); } }