void DrawLink(CustomDrawCellEventArgs e, GraphicsCache cache, string text) { e.DrawDefault(); e.Handled = true; var brush = cache.GetSolidBrush(Color.FromArgb(5, 111, 206)); var font = cache.GetFont(e.Font, FontStyle.Underline); SizeF size = cache.CalcTextSize(text, font, StringFormat.GenericDefault, 0); float height = (float)e.Bounds.Height - size.Height; RectangleF textBounds = new RectangleF(e.Bounds.Left + 8, e.Bounds.Top + height / 2, size.Width + 4, size.Height); cache.DrawString(text, font, brush, Rectangle.Round(textBounds), StringFormat.GenericDefault); }
// Handle the CustomDrawCell event to mark data entry fields with an asterisk. void spreadsheetControl1_CustomDrawCell(object sender, CustomDrawCellEventArgs e) { string cellReference = e.Cell.GetReferenceA1(); if (e.Cell.Worksheet.Name != "Invoice" || (cellReference != "A5" && cellReference != "A10" && cellReference != "F12")) { return; } e.Handled = true; e.DrawDefault(); using (Font font = new Font(e.Font.Name, 14f, FontStyle.Bold)) { string text = "*"; SizeF size = e.Graphics.MeasureString(text, font, Int32.MaxValue, StringFormat.GenericDefault); RectangleF textBounds = new RectangleF(e.Bounds.Right - size.Width - 2, e.Bounds.Bottom - size.Height * 0.7f, size.Width + 2, size.Height); e.Graphics.DrawString(text, font, e.Cache.GetSolidBrush(Color.Red), textBounds, StringFormat.GenericDefault); } }
void DrawErrorTooltip(CustomDrawCellEventArgs e, bool isError) { e.Handled = true; e.DrawDefault(); const int alpha = 255; Color foreColor = GetSemitransparentColor(SystemColors.InfoText, alpha); Color backColor = GetSemitransparentColor(SystemColors.Info, alpha); System.Drawing.Font font = tipFont; Rectangle bounds = e.Bounds; string text = isError ? IncorectData : e.Cell.Formula; SizeF size = e.Graphics.MeasureString(text, font, Int32.MaxValue, StringFormat.GenericDefault); Size tooltipSize = new Size((int)Math.Round(size.Width), (int)Math.Round(size.Height)); Rectangle textBounds = new Rectangle(bounds.X + 1, bounds.Y - tooltipSize.Height - 2, tooltipSize.Width+3, tooltipSize.Height); Rectangle markerBounds = textBounds; markerBounds.Inflate(2, 1); Point[] points = new Point[] { new Point(markerBounds.Left, markerBounds.Top), new Point(markerBounds.Right, markerBounds.Top), new Point(markerBounds.Right, markerBounds.Bottom), new Point(markerBounds.Left + Math.Min(e.FillBounds.Height / 4, markerBounds.Height / 2), markerBounds.Bottom), new Point(markerBounds.Left, markerBounds.Bottom + e.FillBounds.Height / 2), new Point(markerBounds.Left, markerBounds.Top) }; e.Graphics.FillPolygon(e.Cache.GetSolidBrush(backColor), points); e.Graphics.DrawPolygon(e.Cache.GetPen(foreColor), points); e.Graphics.DrawString(text, font, e.Cache.GetSolidBrush(foreColor), textBounds, StringFormat.GenericDefault); }