TMonthCalendar和Delphi样式(Delphi XE2)

phi*_*ext 3 delphi delphi-xe2 vcl-styles

TMontCalendar似乎是一个Windows包装器,所以它不受新VCL样式的影响,你知道它的解决方案吗?

RRU*_*RUZ 6

TMonthCalendarMONTHCAL_CLASS的包装器,据我所知,这个控件不支持所有者绘制,但提供了CalColors允许您设置日历元素颜色的属性,但此属性仅在未启用主题时有效.首先,您必须调用SetWindowTheme函数来禁用日历中的主题,然后您可以设置颜色以匹配vcl样式.

像这样的东西

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;
Run Code Online (Sandbox Code Playgroud)

结果就是这样

在此输入图像描述 在此输入图像描述