/// <summary> /// Paints the cell. /// </summary> /// <param name="graphics"></param> /// <param name="clipBounds"></param> /// <param name="cellBounds"></param> /// <param name="rowIndex"></param> /// <param name="cellState"></param> /// <param name="value"></param> /// <param name="formattedValue"></param> /// <param name="errorText"></param> /// <param name="cellStyle"></param> /// <param name="advancedBorderStyle"></param> /// <param name="paintParts"></param> protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); BeforePaintContent(graphics, cellBounds, cellState, cellStyle, paintParts); if (paintParts.HasFlag(DataGridViewPaintParts.ContentForeground)) { ComboTreeBoxColumn column = (ComboTreeBoxColumn)OwningColumn; ComboTreeNode node = Nodes.ParsePath(Convert.ToString(formattedValue), column.PathSeparator, column.UseNodeNamesForPath); string displayValue; if (column.ShowPath) { displayValue = Convert.ToString(formattedValue); } else { displayValue = (node != null) ? node.Text : String.Empty; } Image img = ComboTreeBox.GetNodeImage(node, column.Images, column.ImageIndex, column.ImageKey, column.ExpandedImageIndex, column.ExpandedImageKey); Rectangle contentBounds = cellBounds; contentBounds.Width -= 17; TextFormatFlags flags = ComboTreeBox.TEXT_FORMAT_FLAGS | TextFormatFlags.PreserveGraphicsClipping; Rectangle imgBounds = (img == null) ? new Rectangle(Point.Add(contentBounds.Location, new Size(1, 0)), Size.Empty) : new Rectangle(contentBounds.Left + 4, contentBounds.Top + (contentBounds.Height / 2 - img.Height / 2), img.Width, img.Height); Rectangle txtBounds = new Rectangle(imgBounds.Right, contentBounds.Top, contentBounds.Right - imgBounds.Right - 3, contentBounds.Height); if (img != null) { graphics.DrawImage(img, imgBounds); } TextRenderer.DrawText(graphics, displayValue, cellStyle.Font, txtBounds, cellStyle.ForeColor, flags); } AfterPaintContent(graphics, clipBounds, cellBounds, rowIndex, cellStyle, advancedBorderStyle, paintParts); }