OnBeforeDrawTitle

Class: TEgDBGridEx

property OnBeforeDrawTitle: TEgDBGridBeforeDrawTitleEvent;

Fired once per title cell, just before it is filled and painted, whenever assigned - the title-row counterpart of OnBeforeDrawCell, same mirrored parameter shape. Never fires for the fixed corner cell (see CornerImageIndex), which has no TColumn of its own.

FontColor, BackColor, and Font arrive already resolved to what the title cell would normally use (VCL Style and Title.Font/Title.Color already applied); change them to override. Font is the actual Canvas.Font about to be used, not a copy. CellText arrives as the raw Title.Caption (still substituted through <var>/<br> at the final paint step, not before - see OnGetVariableValue). ImageIndex/ImageAlignment default from the column’s own TitleImageIndex/ TitleImageAlignment.

Fires before the sort arrow, title image, and title text are drawn, so any override here - including a changed ImageIndex/ImageAlignment - is already in effect for the rest of that cell’s own layout. A BackColor change triggers a flat re-fill first; leaving BackColor untouched lets a themed header element, or a gradient FixedCellStyle, show through underneath exactly as it would without this handler assigned - the same trade-off OnBeforeDrawCell already makes.

If the column has a SubTitle, three further parameters are available: SubTitleFontColor, SubTitleFont (a scratch TFont, freshly copied from the column’s own SubTitleFont before every fire - changes here never leak back into the column’s persistent property, the same safety Font already has for the main title), and SubTitleText (defaults to the raw SubTitle, parsed the same way CellText is). Setting SubTitleText to an empty string suppresses that column’s SubTitle for this one paint - but the event cannot make a column show a SubTitle that was empty to begin with, since row height is only reserved for a SubTitle that is statically non-empty.

After both handlers have run (grid then column), SubTitleFontColor can still change once more: if it ends up too close in perceived brightness to the cell’s own final BackColor, it is automatically nudged lighter or darker to restore legibility, whether the handler set it explicitly or left the resolved default in place. A handler that needs its exact color to reach the screen unmodified should make sure that color already has enough contrast against BackColor itself.

Replaces the older OnDrawTitleImage, which only covered the title image and had no color, font, or text control. Also available at column level (see TEgColumn.OnBeforeDrawTitle); when both are assigned, the grid-level handler runs first. See TEgDBGridBeforeDrawTitleEvent.

See Also

(C) 2026 Easygate, Lda