3

TMontCalendar seems to be a Windows wrapper so it can't be affected by the new VCL Styles, do you know a solution for it ?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
philnext
  • 3,242
  • 5
  • 39
  • 62
  • 3
    Until RRUZ gives you the solution you might want to read about [vcl-styles-and-owner-draw](http://theroadtodelphi.wordpress.com/2012/03/14/vcl-styles-and-owner-draw/). In particular [TStyleHook](http://docwiki.embarcadero.com/Libraries/en/Vcl.Themes.TStyleHook). – LU RD Apr 10 '12 at 13:16
  • 1
    Here is someone who hacked TWebBrowser to use VCL styles: http://theroadtodelphi.wordpress.com/2012/03/20/delphi-vcl-styles-and-twebbrowser-source-code-released/ – Jan Doggen Apr 10 '12 at 13:20
  • 1
    And this may also help http://theroadtodelphi.wordpress.com/2012/03/14/vcl-styles-and-owner-draw/ – Jan Doggen Apr 10 '12 at 13:23
  • @all : I saw these (excellent) posts, but I would know if htere was a more elegant & simple solution. – philnext Apr 10 '12 at 14:58

1 Answers1

6

The TMonthCalendar is wrapper for the MONTHCAL_CLASS and as far i know this control doesn't support owner draw, but provides the CalColors property which allow you to set the colors of the elements of the calendar, but this property only works when the themes is not enabled. So first you must call the SetWindowTheme function to disable the themes in the calendar and then you can set the colors to match with the vcl styles.

Something like this

uses
  Vcl.Styles,
  Vcl.Themes,
  uxTheme;

Procedure SetVclStylesColorsCalendar( MonthCalendar: TMonthCalendar);
Var
  LTextColor, LBackColor : TColor;
begin
   uxTheme.SetWindowTheme(MonthCalendar.Handle, '', '');//disable themes in the calendar
   MonthCalendar.AutoSize:=True;//remove border

   //get the vcl styles colors
   LTextColor:=StyleServices.GetSystemColor(clWindowText);
   LBackColor:=StyleServices.GetSystemColor(clWindow);

   //set the colors of the calendar
   MonthCalendar.CalColors.BackColor:=LBackColor;
   MonthCalendar.CalColors.MonthBackColor:=LBackColor;
   MonthCalendar.CalColors.TextColor:=LTextColor;
   MonthCalendar.CalColors.TitleBackColor:=LBackColor;
   MonthCalendar.CalColors.TitleTextColor:=LTextColor;
   MonthCalendar.CalColors.TrailingTextColor:=LTextColor;
end;

And the result will be this

enter image description here enter image description here

RRUZ
  • 134,889
  • 20
  • 356
  • 483