TMonthCalendar& Delphi样式(Delphi XE2)

时间:2012-04-10 12:52:50

标签: delphi delphi-xe2 vcl-styles

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

1 个答案:

答案 0 :(得分: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;

结果将是这个

enter image description here enter image description here