TMonthCalendar和Delphi样式(Delphi XE2)

3

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


3
在RRUZ给出解决方案之前,您可能需要阅读有关vcl-styles-and-owner-draw的内容。特别是TStyleHook部分。 - LU RD
1
这是一个把TWebBrowser黑进去以使用VCL样式的人: http://theroadtodelphi.wordpress.com/2012/03/20/delphi-vcl-styles-and-twebbrowser-source-code-released/ - Jan Doggen
1
这可能也会有所帮助:http://theroadtodelphi.wordpress.com/2012/03/14/vcl-styles-and-owner-draw/ - Jan Doggen
@所有人:我看到了这些(优秀的)帖子,但我想知道是否有更加简洁和优雅的解决方案。 - philnext
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;

而结果将是这个

enter image description here enter image description here


好的,我差不多也明白了。但是你的表述更清晰、更聪明! - philnext

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接