簡體   English   中英

Delphi FMX TCalendar-禁用周末

[英]Delphi FMX TCalendar - Disable Weekends

是否可以從FMX TCalendar組件禁用某些日期? 例如周末
如果可以將其高亮顯示為已禁用,這也很好,例如,下圖中的第14天和第15天

在此處輸入圖片說明

我可以通過在點擊測試打開的情況下在listboxitemstyle上添加一個矩形來禁用它
這就是我為上面的圖片所做的

procedure TForm1.cal1DayClick(Sender: TObject);
var sTemp : String;
begin
  cal1.StylesData['days.Selected.StyleLookup'] := 'ListBoxItemstyleCust';
end;

但是我不知道如何在創建項目時訪問styleslistbox項目,即使這是我應該做的方式

經過一段時間的探索,這是對我在這里找到的源代碼的快速解釋

\\ Embarcadero \\ Studio \\ 17.0 \\ source \\ fmx文件夾中有一個FMX.Calendar.Style.pas文件

我已將該文件復制到與項目相同的位置,並將其重命名為My.FMX.Calendar.Style.pas

我還已將TStyledCalendar重命名為TMyStyledCalendar,然后將初始化和最終化從

initialization
  TPresentationProxyFactory.Current.Register(TCalendar, TControlType.Styled, TStyledPresentationProxy<TMyStyledCalendar>);
finalization
  TPresentationProxyFactory.Current.Unregister(TCalendar, TControlType.Styled, TStyledPresentationProxy<TMyStyledCalendar>);
end.

initialization
  TPresentationProxyFactory.Current.Unregister(TCalendar, TControlType.Styled, TStyledPresentationProxy<TStyledCalendar>);
  TPresentationProxyFactory.Current.Register(TCalendar, TControlType.Styled, TStyledPresentationProxy<TMyStyledCalendar>);
finalization
  TPresentationProxyFactory.Current.Unregister(TCalendar, TControlType.Styled, TStyledPresentationProxy<TMyStyledCalendar>);

還在使用部分添加了FMX.Calendar.Style
在程序FillDays中; 創建了一個新程序

  procedure ChangeStyle(aDay : TDateTime;Item: TDayItem);
  var wDay : Word;
  begin
    wDay := DayOfWeek(aDay-1);
    if (wDay = DaySaturday) or (wday = DaySunday) then begin
      item.Enabled := false;
      if (Item.StyleLookup <> 'MyListBoxItemstyle') then
        Item.StyleLookup := 'MyListBoxItemstyle';
    end else begin
      if (Item.StyleLookup <> '') then
        Item.StyleLookup := '';
    end;
  end;

並添加了ChangeStyle(Item.Date,Item); 到以下FillDaysOfPreviousMonth; FillDaysOfCurrentMonth; FillDaysOfNextMonth;

添加了樣式以匹配MyListBoxItemstyle

風格日歷

在使用樣式后,它看起來像這樣 風格日歷v2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM