【问题标题】:Delphi FMX TCalendar - Disable WeekendsDelphi FMX TCalendar - 禁用周末
【发布时间】:2015-11-18 01:54:04
【问题描述】:

是否可以从 FMX TCalendar 组件中禁用某些日期? 例如周末
如果可以突出显示他们被禁用,例如下图中的第 14 天和第 15 天

我可以通过在 listboxitemstyle 上添加一个矩形并启用命中测试来禁用它
这就是我为上图所做的

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

但我不知道如何在创建项目时访问样式列表框项目,即使这是我应该这样做的方式

【问题讨论】:

  • Embarcadero 是否使用比几年前给出的答案更好的方法为 10.3 创建了更新的 FMX TCalendar?

标签: android ios delphi calendar firemonkey


【解决方案1】:

经过一段时间的挖掘,这是对我发现的内容的快速解释 Source code here

在文件夹中 \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

在玩过这些样式之后,它看起来像这样

【讨论】:

    猜你喜欢
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多