cxDateNavigator1 set weekend days text color in red

风流意气都作罢 提交于 2019-12-11 04:06:00

问题


In TcxDateNavigator, is it possible to mark the weekend (Saturday, Sunday) with a diffrent text color (red)?

TMS has this feature implemented but I can't seem to find that in this DevExpress component.


回答1:


As for the cxDateNavigator, you can use its OnCustomDrawDayNumber event handler, for instance, as follows:

uses
  DateUtils, cxDateUtils;

procedure TForm60.cxDateNavigator1CustomDrawDayNumber(Sender: TObject; ACanvas: TcxCanvas; AViewInfo: TcxSchedulerDateNavigatorDayNumberViewInfo; var ADone: Boolean);
begin
  if DayOfTheWeek(AViewInfo.Date) in [DaySaturday, DaySunday] then
  begin
    AViewInfo.Bold := True;
    ACanvas.Font.Color := clGreen;
    ACanvas.Brush.Color := clYellow;
  end;
end;

I would not recommend you to use red for weekends, because it usally indicates a holiday.

And if you want to know which date you are pointing at with you mouse. You can implement a OnMouseMoveevent:

procedure TForm60.cxDateNavigator1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  dt: TDateTime;
begin
  dt := TcxDateNavigator(Sender).HitTest.Time;
  if dt = NullDate then
    Caption := 'You are pointing outside the calendar area'
  else
    Caption := 'You are pointing at ' + FormatDateTime(FormatSettings.LongDateFormat, dt);

end;


来源:https://stackoverflow.com/questions/29482437/cxdatenavigator1-set-weekend-days-text-color-in-red

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