3

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

4

1 回答 1

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;

结果将是这样

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

于 2012-04-10T15:21:25.383 回答