cxDateNavigator1将周末天文本颜色设置为红色

时间:2015-04-07 01:51:13

标签: delphi devexpress tcxgrid

在TcxDateNavigator中,是否可以用不同的文字颜色(红色)标记周末(周六,周日)?

TMS已实现此功能,但我似乎无法在此DevExpress组件中找到它。

1 个答案:

答案 0 :(得分:3)

对于cxDateNavigator,您可以使用其OnCustomDrawDayNumber事件处理程序,例如,如下所示:

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;

enter image description here

我不建议你在周末使用红色,因为它通常表示假期。

如果你想知道你用鼠标指着哪个日期。您可以实施OnMouseMove事件:

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;