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 项目,即使这是我应该做的方式
经过一段时间的挖掘,这是对我发现的内容的快速解释
Source code here
文件夹中
\Embarcadero\Studio.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
调整样式后,它看起来像这样
是否可以从 FMX TCalendar 组件中禁用某些日期?
例如周末
如果可以突出显示它们已被禁用,这也将是一件好事,例如下图中的第 14 天和第 15 天
我可以通过在命中测试打开的情况下将矩形添加到 listboxitemstyle 来禁用它
这就是我为上图所做的
procedure TForm1.cal1DayClick(Sender: TObject);
var sTemp : String;
begin
cal1.StylesData['days.Selected.StyleLookup'] := 'ListBoxItemstyleCust';
end;
但我不知道如何在创建项目时访问 styleslistbox 项目,即使这是我应该做的方式
经过一段时间的挖掘,这是对我发现的内容的快速解释 Source code here
文件夹中 \Embarcadero\Studio.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
调整样式后,它看起来像这样