Delphi FireMonkey的日期和日历控件TCalendarEdit、TCalendar星期都显示的比较长,导致显示混乱根本看不清是星期几。

闲话少说,修正方法是在delphi的安装目录中找到source\fmx\FMX.ExtCtrls.pas并打开。

找到这段

for i := 0 to 6 do
    begin
       TLabel(FWeek.Children[i]).Text := FormatSettings.ShortDayNames
          [1 + ((7 + i + FFirstDayOfWeekNum) mod 7)];
    end; 

然后对这段代码进行改造就可以啦,修改结果如下:

for I := 0 to 6 do

    begin

      WeekCaption := FormatSettings.ShortDayNames

        [1 + ((7 + I + FFirstDayOfWeekNum) mod 7)];

{$IFDEF MACOS}

      TLabel(FWeek.Children[I]).Text := WeekCaption;

{$ELSE}

      if SysLocale.DefaultLCID = $0804 then

      begin

        TLabel(FWeek.Children[I]).Text := Copy(WeekCaption, 3, 1);

      end

      else

      begin

        TLabel(FWeek.Children[I]).Text := WeekCaption;

      end;

 {$ENDIF}

    end;

另外在该代码所在方法声明部分还需要加上对WeekCaption的定义

procedure TCalendar.FillList;

var

  i: Integer;

  AYear, PreMonth, AMonth, ADay: Word;

  Date: TDate;

  First: Integer;

  A: string;

  WeekCaption:string;

  Item: TListBoxItem;

  LocaleService: IFMXLocaleService;

begin

  ..........

end

最后,将FMX.ExtCtrls.pas重新编译一下,将生成的FMX.ExtCtrls.dcu替换Delphi安装目录中的相应文件

---XE 10.2版本有所调整,修改的地方在 FMX.Calendar.Style文件中

修改后结果如下

procedure TStyledCalendar.FillWeekDays;
var
  I: Integer;
  Day: Integer;
  CaptionControl: ICaption;
 FullCation:string;
begin
  if FWeek = nil then
    Exit;

  for I := 0 to DaysPerWeek - 1 do
    if Supports(FWeek.Controls[I], ICaption, CaptionControl) then
    begin
      Day := (I + FFirstDayOfWeekNum) mod DaysPerWeek;

     //CaptionControl.Text :=(I + FFirstDayOfWeekNum) mod DaysPerWeek;
     FullCation:=FormatSettings.ShortDayNames[1 + Day];
      if pos('周',FullCation)=1 then
        CaptionControl.Text :=Copy(FullCation, 2, 1)
      else if  pos('星期',FullCation)=1 then
        CaptionControl.Text :=Copy(FullCation, 3, 1)
      else CaptionControl.Text :=FullCation;
    end;
end;


本文由 王守红 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

还不快抢沙发

添加新评论