TMonthCalendar & Delphi Styles (Delphi XE2)

左心房为你撑大大i 提交于 2019-12-12 13:18:37

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/10089189/tmonthcalendar-delphi-styles-delphi-xe2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!