The problem starts in TCustomLabel.AdjustBounds
with a call to DoDrawText
with the screen's device context and the flag DT_CALCRECT. So if anything paints on that device context, it will be painted onto the screen. The DT_CALCRECT
flag should prevent that but the DrawThemeTextEx
call in Vcl.Themes.TUxThemeStyle.DoDrawText
seems to ignore the DT_CALCRECT + LOptions.dwFlags DTT_CALCRECT and paints onto the device context where it should only calculate the required rectangle. I don't know why DrawThemeTextEx
does that (yet), but it is a starting point.
UPDATE 1:
Delphi 2009 doesn't seem to be affected by this but also calls DrawThemeTextEx. The only difference I see is that all unused fields of the Options record are zero whereas in Delphi XE2 they contain garbage. Maybe DrawThemeTextEx needs them to be zero.
UPDATE 2:
The difference between Delphi 2009 and XE2 is that in Delphi 2009 not only DTT_CALCRECT is specified but also DTT_COMPOSITE.
In Delphi 2009 the DTT_COMPOSITE is always set:
Options.dwFlags := DTT_TEXTCOLOR or DTT_COMPOSITED or DTT_GLOWSIZE;
whereas in XE2 the flag is only set if the label is painted on glass:
if csGlassPaint in ControlState then
Include(LFormat, tfComposited);
DrawThemeTextEx
withDT_CALCRECT
. I imagine that is only done when there's the need to calculate the size of the label = when the label'sAutoSize
isTrue
. If you turn ofAutoSize
, no call withDT_CALCRECT
is performed and, consequently, the bug is not produced. – Spritsail