Question

I guess this is yet another reason why VCL styles are not ready to be really used.

TDateTimePicker control looks fine without VCL styles. Turn on any vcl style, and I get this appearance:

enter image description here

I can turn off the vcl styles for just this component type, by registering a style hook, but that looks really ugly.

This is on Delphi XE2 with update 4 installed.

Ideally, I hope there is a workaround, or some properties of the datetime picker, or some subclass of datetimepicker I could do to force the datetime picker to paint and theme correctly.

Note that normal comboboxes are theming correctly. Note that this reproduces easily in the most minimal sample project imaginable. Yes. It's Yet Another Styles bug.

Update It might be platform specific, related to Windows Common Controls versions on Windows Server 2008 R2 without Aero ("Desktop Experience" in Windows server component terms). It just occurred to me after other people cannot reproduce it, to try this on several different Windows machines. After I did that, I find that the problem only reproduces on Windows Server 2008 R2. Some of our customers use Windows Server 2008 R2. As you know a major reason for using VCL Styles is that it makes your app look the same regardless of what the windows theme is. However in the case above, the whole app themes properly, except the DateTimePicker control, which is themed incorrectly, and only on Windows Server 2008 R2. The same XE2-based demo app works fine on Windows 7.

Both the working and non-working systems have a ComCtl32.dll in the SysWow64 folder with version reading 5.82.7601.17514. However, clearly the native layout and appearance of these controls is different, when VCL themes are off, and this affects the skinning code, which fails.

Update2: Reported as a bug: QC Entry 106783

Was it helpful?

Solution

Ok, I just made a small change to the Vcl.Styles.DateTimePickers unit which is part of the vcl-styles-utils. To fix this issue when the "Windows Classic" theme is active.

Use this style hook in this way

uses
  Vcl.Styles,
  Vcl.Themes,
  Vcl.Styles.DateTimePickers;

initialization
 TStyleManager.Engine.RegisterStyleHook(TDateTimePicker, TDateTimePickerStyleHookFix);

And this will be the result.

enter image description here

OTHER TIPS

I can confirm that when I install Desktop Experience, enable Themes and start the Themes service, this glitch goes away.

Okay here's my workaround code for now:

function DetectWin7Or2008R2ClassicTheme:Boolean;
begin

   if  ( Win32MajorVersion>=6 ) then
      result := (not Themes.ThemeServices.ThemesEnabled) // and IsServerOs
   else
      result := false;


end;


// main form initialization section:


initialization
 if DetectWin7Or2008R2ClassicTheme then
 TStyleManager.Engine.RegisterStyleHook(TDateTimePicker, TStyleHook); {no theme!}
end.

It's clearly a wild corner-case. I expect to find more, and I'll come back and update this question when I find what else breaks on Windows Server 2008R2 or Windows 7, when the theme service is not running, which is what happens when you pick "Windows Classic Theme" on Win7, also.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top