/// <returns> True if painting is handled (should skip default). </returns> protected virtual bool DoPrePaintItem(PaintTreeItemEventArgs args) { if (args.Node != null) { using (Brush brush = new SolidBrush(SystemColors.Window)) { args.Graphics.FillRectangle(brush, args.Bounds); } if (OnPrePaintItem != null) { OnPrePaintItem(this, args); } } return(false); }
protected virtual void DoPostPaintItem(PaintTreeItemEventArgs args) { if (args.Node != null) { Rectangle bounds = args.Node.Bounds; bounds.Height -= 1; if (args.Focused) { using (Brush brush = new SolidBrush(Color.FromArgb(70, SystemColors.Highlight))) { args.Graphics.FillRectangle(brush, bounds); } } if (args.Selected) { args.Graphics.DrawRectangle(SystemPens.Highlight, bounds); } if (OnPostPaintItem != null) { OnPostPaintItem(this, args); } } }
private bool NotifyTreeCustomDraw(ref Message message) { message.Result = (IntPtr)CustomDrawReturnFlags.CDRF_DODEFAULT; NMTVCUSTOMDRAW customDrawInfo = (NMTVCUSTOMDRAW)message.GetLParam(typeof(NMTVCUSTOMDRAW)); IntPtr thisHandle = Handle; if (customDrawInfo.nmcd.hdr.hwndFrom == Handle) { switch (customDrawInfo.nmcd.dwDrawStage) { case (int)CustomDrawDrawStateFlags.CDDS_PREPAINT: message.Result = (IntPtr)CustomDrawReturnFlags.CDRF_NOTIFYITEMDRAW; break; case (int)CustomDrawDrawStateFlags.CDDS_ITEMPREPAINT: message.Result = (IntPtr)CustomDrawReturnFlags.CDRF_NOTIFYPOSTPAINT; PaintTreeItemEventArgs args = GetPaintTreeItemEventArgs(customDrawInfo); try { args.ForeColor = SystemColors.WindowText; args.BackColor = SystemColors.Window; if (DoPrePaintItem(args)) { DoPostPaintItem(args); message.Result = (IntPtr)CustomDrawReturnFlags.CDRF_SKIPDEFAULT; } customDrawInfo.clrTextBk = RGB ( args.BackColor.R, args.BackColor.G, args.BackColor.B ); customDrawInfo.clrText = RGB ( args.ForeColor.R, args.ForeColor.G, args.ForeColor.B ); Marshal.StructureToPtr(customDrawInfo, message.LParam, true); } finally { args.Graphics.Dispose(); } break; case (int)CustomDrawDrawStateFlags.CDDS_ITEMPOSTPAINT: args = GetPaintTreeItemEventArgs(customDrawInfo); try { DoPostPaintItem(args); } finally { args.Graphics.Dispose(); } break; } } return(false); }