bool NotifyHeaderCustomDraw(ref Message m) { m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_DODEFAULT; NMCUSTOMDRAW nmcd = (NMCUSTOMDRAW)m.GetLParam(typeof(NMCUSTOMDRAW)); if (nmcd.hdr.hwndFrom != hHeader) { return(false); } switch (nmcd.dwDrawStage) { case (int)CustomDrawDrawStateFlags.CDDS_PREPAINT: // Ask for Item painting notifications m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_NOTIFYITEMDRAW; break; case (int)CustomDrawDrawStateFlags.CDDS_ITEMPREPAINT: DoHeaderCustomDrawing(ref m); break; case (int)NotificationMessages.NM_NCHITTEST: break; default: break; } return(false); }
internal void HandleColumnsDrawing(TreeListNode tlNode, NMCUSTOMDRAW cd) { RECT newRect = cd.rc; // Make text align correctly - seems to be off a pixel newRect.top += 1; using (Graphics g = Graphics.FromHdc(cd.hdc)) { // Do each of the columns defined for the tree for (int i = 0; i < _treeView.Columns.Count; i++) { newRect.left = cd.rc.left + ((Splitter)_columnHeaderSplitters[i]).Bounds.X - _scrollPos; Object colData = tlNode.ColumnData[i]; if (i == 0) { // Clear out the data for the column (first time) g.FillRectangle(SystemBrushes.Window, newRect.left - PIXEL_PADDING, cd.rc.top, cd.rc.right, cd.rc.bottom); } // Vertical line to separate the columns g.DrawLine(_greyPen, newRect.left, cd.rc.top, newRect.left, cd.rc.bottom); // Write the actual text if (colData != null) { // Start the text one pixel after the line newRect.left += PIXEL_PADDING; g.DrawString(colData.ToString(), _treeView.Font, SystemBrushes.ControlText, newRect.left, newRect.top); } } // Draw the horizontal grid lines g.DrawLine(_greyPen, cd.rc.left, cd.rc.top, cd.rc.right, cd.rc.top); g.DrawLine(_greyPen, cd.rc.left, cd.rc.bottom, cd.rc.right, cd.rc.bottom); } }
bool NotifyListCustomDraw(ref Message m) { m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_DODEFAULT; NMCUSTOMDRAW nmcd = (NMCUSTOMDRAW)m.GetLParam(typeof(NMCUSTOMDRAW)); //IntPtr thisHandle = Handle; if (nmcd.hdr.hwndFrom != Handle) { return(false); } switch (nmcd.dwDrawStage) { case (int)CustomDrawDrawStateFlags.CDDS_PREPAINT: // Ask for Item painting notifications m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_NOTIFYITEMDRAW; break; case (int)CustomDrawDrawStateFlags.CDDS_ITEMPREPAINT: m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_NOTIFYSUBITEMDRAW; break; case (int)(CustomDrawDrawStateFlags.CDDS_ITEMPREPAINT | CustomDrawDrawStateFlags.CDDS_SUBITEM): // Draw background DoListCustomDrawing(ref m); break; default: break; } return(false); }
/// <summary> /// /// </summary> /// <param name="m"></param> protected override void WndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case WM_NOTIFY: { base.WndProc(ref m); NMHDR nm1 = ( NMHDR )m.GetLParam(typeof(NMHDR)); switch (nm1.code) { case ( int )NotificationMessages.NM_CUSTOMDRAW: { m.Result = ( IntPtr )CustomDrawReturnFlags.CDRF_DODEFAULT; NMCUSTOMDRAW nmcd = ( NMCUSTOMDRAW )m.GetLParam(typeof(NMCUSTOMDRAW)); switch (nmcd.dwDrawStage) { case ( int )CustomDrawDrawStateFlags.CDDS_PREPAINT: CddsPrePaint(ref m); break; case ( int )CustomDrawDrawStateFlags.CDDS_POSTPAINT: CddsPostPaint(ref m); break; case ( int )CustomDrawDrawStateFlags.CDDS_ITEMPREPAINT: CddsItemPrePaint(ref m); break; case ( int )CustomDrawDrawStateFlags.CDDS_ITEMPOSTPAINT: CddsItemPostPaint(ref m); break; case ( int )CustomDrawDrawStateFlags.CDDS_SUBITEMPREPAINT: CddsSubItemPrePaint(ref m); break; case ( int )CustomDrawDrawStateFlags.CDDS_SUBITEMPOSTPAINT: CddsSubItemPostPaint(ref m); break; } } break; } } break; default: base.WndProc(ref m); break; } }
protected override void WndProc(ref Message m) { switch (m.Msg) { case Windows.WM_NOTIFY: { NMHDR nmhdr = (NMHDR)m.GetLParam(typeof(NMHDR)); switch (nmhdr.code) { case Windows.NM_CUSTOMDRAW: { NMCUSTOMDRAW cd = (NMCUSTOMDRAW)m.GetLParam(typeof(NMCUSTOMDRAW)); switch (cd.dwDrawStage) { case Windows.CDDS_PREPAINT: // Tell windows we want to see the POSTPAINT event m.Result = (IntPtr)Windows.CDRF_NOTIFYITEMDRAW; _scrollPos = Windows.GetScrollPos(cd.nmcd.hwndFrom, Windows.SB_HORZ); SetupTopPanelSizes(); return; case Windows.CDDS_ITEMPREPAINT: // Tell windows we want to see the POSTPAINT event m.Result = (IntPtr)Windows.CDRF_NOTIFYPOSTPAINT; return; case Windows.CDDS_ITEMPOSTPAINT: TreeNode node = _treeView.GetNodeFromHandle(cd.dwItemSpec); if (node is TreeListNode) { HandleColumnsDrawing((TreeListNode)node, cd); } break; default: break; } break; } } break; } } base.WndProc(ref m); }
/// <summary> /// /// </summary> /// <param name="m"></param> protected virtual void CddsItemPostPaint(ref System.Windows.Forms.Message m) { NMCUSTOMDRAW nmcd = ( NMCUSTOMDRAW )m.GetLParam(typeof(NMCUSTOMDRAW)); int iColumn = nmcd.dwItemSpec; Rectangle rcHeader = new Rectangle(nmcd.rc.left, nmcd.rc.top, nmcd.rc.right - nmcd.rc.left, nmcd.rc.bottom - nmcd.rc.top); using (Graphics g = Graphics.FromHdc(nmcd.hdc)) { ColumnHeaderPaintEventArg pe = new ColumnHeaderPaintEventArg(g, rcHeader, this.Columns[iColumn]); OnColumnHeaderPaint(pe); } // free resources and say to control skip default drawing m.Result = ( IntPtr )CustomDrawReturnFlags.CDRF_SKIPDEFAULT; }
void DoHeaderCustomDrawing(ref Message m) { NMCUSTOMDRAW nmcd = (NMCUSTOMDRAW)m.GetLParam(typeof(NMCUSTOMDRAW)); using (Graphics g = Graphics.FromHdc(nmcd.hdc)) { Rectangle rc = GetHeaderCtrlRect(); rc = GetHeaderItemRect(nmcd.dwItemSpec); int itemRight = rc.Left + rc.Width; g.FillRectangle(new SolidBrush(SystemColors.ScrollBar), rc.Left, rc.Top, rc.Width, rc.Height); if (nmcd.dwItemSpec == PressedHeaderItem && !IsCursorOnDivider() && Tracking == false) { PressedHeaderItem = -1; rc.Inflate(-1, -1); g.FillRectangle(new SolidBrush(ColorUtil.VSNetPressedColor), rc.Left, rc.Top, rc.Width, rc.Height); } else { ControlPaint.DrawBorder3D(g, rc.Left, rc.Top, rc.Width, rc.Height - 1, Border3DStyle.RaisedInner, Border3DSide.All); } string text = GetHeaderItemText(nmcd.dwItemSpec); Debug.WriteLine(text); Size textSize = TextUtil.GetTextSize(g, text, Font); int gap = 4; Point pos = new Point(rc.Left + gap, rc.Top + ((rc.Height - textSize.Height) / 2)); int headerImageIndex; if (headerIconsList != null && HasHeaderImage(nmcd.dwItemSpec, out headerImageIndex)) { if (headerImageIndex != -1) { Image image = headerImageList.Images[headerImageIndex]; if (image != null) { g.DrawImage(headerImageList.Images[headerImageIndex], rc.Left + gap, rc.Top); pos.X += IMAGE_WIDTH; rc.Width = rc.Width - IMAGE_WIDTH; } } } // Draw arrow glyph if (nmcd.dwItemSpec == lastSortedColumn) { int Left = pos.X + 2; Left += textSize.Width + TEXT_TO_ARROW_GAP; Rectangle arrowRect = new Rectangle(Left, rc.Top, ARROW_WIDTH, rc.Height); if (itemRight >= (Left + ARROW_WIDTH + 4)) { if (Sorting == SortOrder.Ascending || Sorting == SortOrder.None) { DrawUpArrow(g, arrowRect); } else { DrawDownArrow(g, arrowRect); } } } // I use the Windows API instead of the Graphics object to draw the string // because the Graphics object draws ellipes without living blank spaces in between // the DrawText API adds those blank spaces in between int ellipsingTringgering = 8; Rectangle drawRect = new Rectangle(pos.X + 2, pos.Y, rc.Width - gap - ellipsingTringgering, rc.Height); TextUtil.DrawText(g, text, Font, drawRect); } m.Result = (IntPtr)CustomDrawReturnFlags.CDRF_SKIPDEFAULT; }
public extern static int RtlMoveMemory( ref NMCUSTOMDRAW destination, IntPtr Source, int length);
private extern static int RtlMoveMemory(ref NMCUSTOMDRAW Destination, IntPtr Source, int Length);
protected override IntPtr OnNotify(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam) { if (prevWndProc == IntPtr.Zero) { return(IntPtr.Zero); } NMCUSTOMDRAW nmcd = (NMCUSTOMDRAW)Marshal.PtrToStructure(lParam, typeof(NMCUSTOMDRAW)); //System.Diagnostics.Debug.WriteLine(string.Format("{0}", (NM)nmcd.hdr.code)); if (nmcd.hdr.code == (int)NM.DBLCLK) { OnDoubleClick(EventArgs.Empty); return(IntPtr.Zero); } if (nmcd.hdr.code != (int)NM.CUSTOMDRAW || nmcd.hdr.hwndFrom != control.Handle) { return(Win32Window.CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam)); } CustomDrawType cd = (CustomDrawType)Marshal.PtrToStructure(lParam, typeof(CustomDrawType)); //System.Diagnostics.Debug.WriteLine(cd.dwDrawStage); try { switch (cd.dwDrawStage) { case CDDS.PREPAINT: if (FullPaint && !OnPrepaint(ref cd)) { return((IntPtr)CDRF.DODEFAULT); } return((IntPtr)(CDRF.NOTIFYITEMDRAW | CDRF.NOTIFYPOSTERASE | CDRF.NOTIFYSUBITEMDRAW | CDRF.NOTIFYPOSTPAINT)); case CDDS.ITEMPREPAINT: //if (listView.View == View.Details) // return (int)CDRF.NOTIFYSUBITEMDRAW; if (!OnPrepaintItem(ref cd)) { return((IntPtr)CDRF.DODEFAULT); } if (fullPaint) { return((IntPtr)(CDRF.SKIPDEFAULT)); } else { return((IntPtr)(CDRF.NOTIFYSUBITEMDRAW)); } case CDDS.SUBITEMPREPAINT: if (!OnPrepaintItem(ref cd)) { return((IntPtr)CDRF.DODEFAULT); } if (fullPaint) { return((IntPtr)(CDRF.SKIPDEFAULT)); } else { return((IntPtr)(CDRF.NOTIFYITEMDRAW)); } case CDDS.ITEMPOSTPAINT: return((IntPtr)(CDRF.SKIPDEFAULT)); case CDDS.PREERASE: if (fullPaint || !OnPreerase(ref cd)) { return((IntPtr)CDRF.DODEFAULT); } return((IntPtr)(CDRF.NOTIFYPOSTERASE)); } } finally { Marshal.StructureToPtr(cd, lParam, false); } return((IntPtr)CDRF.DODEFAULT); }
public static extern int RtlMoveMemory(ref NMCUSTOMDRAW destination, IntPtr Source, int length);