程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 使用 IntraWeb (22)

使用 IntraWeb (22)

編輯:Delphi


TIWCalendar: 日歷控件, 繼承於 TIWCustomGrid, 所以它和 TIWGrid 共同屬性特多.

它的 Cell 是 TIWCalendarCell 對象, 直接從 TIWGridCell 繼承.



TIWCalendar 所在單元及繼承鏈:
IWCompCalendar.TIWCalendar < TIWCustomGrid < TIWCustomControl < TIWBaseHTMLControl < TIWBaseControl < TIWVCLBaseControl < TControl < TComponent < TPersistent < TObject

主要成員:
property Cell[const ARow: Integer, const AColumn: Integer]: TIWCalendarCell //
property CurrentDayImage: TIWFileReference    //顯示在當前日期的圖片
property CaptionToday: string                 //當前日期的附加標題
property PreviousMonthImage: TIWFileReference //"後退"圖片
property NextMonthImage: TIWFileReference     //"前進"圖片
property CaptionPrevious: string          //"後退"標題
property CaptionNext: string              //"前進"標題
property CalendarHeaderColor: TIWColor    //標題背景色
property CalendarColor: TIWColor          //背景色
property AlternateCalendarColor: TIWColor //用於交替的背景色
property CheckerBoard: Boolean            //是否使用交替背景
property CalendarHeaderFont: TIWFont  //標題字體
property CalendarFont: TIWFont        //字體
property StartDate: TDateTime         //默認當前日期
property SelectedDate: TDateTime      //就是剛剛點過的日期
property DisplayYear: Boolean         //是否顯示"年"
property LocaleID: Integer                 //本地語言 ID

property CellRenderOptions: TIWCellRenderOptions //
property BorderColors: TIWGridBorderColors //
property BGColor: TIWColor                 //
property BorderSize: Integer               //
property BorderStyle: TIWGridBorderStyle   //
property Caption: TCaption     //
property CellPadding: Integer  //          
property CellSpacing: Integer  //
property Font: TIWFont         //
property Lines: TIWGridLines   //
property Summary: string       //
property UseFrame: Boolean     //
property UseSize: Boolean      //
property HiddenColumns: TStringList //

property OnDateChange: TIWCalendarDateChange     //
property OnGetDateInformation: TIWCalendarGetDateInformation  //
property OnGetDayNames: TIWCalendarGetDayNames   //
property OnGetMonthName: TIWCalendarGetMonthName //
property OnRenderCell: TIWOnRenderCell           //
property OnRender: TNotifyEvent                  //
property OnGetCellRenderOptions: TIWGetCellRenderOptionsEvent //

procedure SetHeaderCells;                                          //
function IsRowVisible(ARow: Integer): Boolean                      //
procedure SetColumnVisibility(AColumn: Integer; AVisible: Boolean) //


TIWCalendarCell:

{IWCompCalendar.TIWCalendarCell < TIWGridCell < TCollectionItem < TPersistent < TObject}

property CellDate: TDateTime          //
property DateInformation: TStringList //與日期關聯的備注信息
property ImageFile: TIWImageFile      //看來每個 Cell 都可以使用圖像; 這應該是為當前日期准備的

{還包括和 TIWGridCell 相同的一些}


改控件拖到窗體上就能用, 如果要寫一行代碼的話應該是: IWCalendar1.StartDate := Date;

下面是個比較全面的測試:
var
  gInfoList: TStrings; //用於記錄自定義的備忘信息

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  gInfoList := TStringList.Create; //如果是長期保存, 它應該是從服務器上讀取某個文件

  IWCalendar1.Caption := '';           //標題無用
  IWCalendar1.CaptionPrevious := '<<'; //其實給它圖像(PreviousMonthImage)更好看
  IWCalendar1.CaptionNext := '>>';

  IWCalendar1.CalendarHeaderColor := $88aaaa;

  IWCalendar1.CalendarColor := $eeffff;
  IWCalendar1.AlternateCalendarColor := $ccdddd; //交替顏色
  IWCalendar1.CheckerBoard := True;              //確認使用指定的 "交替顏色" 與背景色交替使用

  IWCalendar1.CalendarFont.Size := 12;
  LinkColor := $0033dd; //Cell 中的文本其實成了鏈接了, 如果要改變 Cell 中文本的顯示, 最好使用 Css

  IWCalendar1.CaptionToday := '★'; //突出標示當前日期, 或使用圖像(CurrentDayImage)

  IWCalendar1.StartDate := Date; //顯然使用 Date 比 Now 更合理; 這句還能起到刷新的作用
end;

{通過 OnGetDayNames 事件調整周標題顯示}
procedure TIWForm1.IWCalendar1GetDayNames(var Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday: string);
begin
  Sunday := '周末';
end;

{通過 OnGetMonthName 事件調整月份顯示}
procedure TIWForm1.IWCalendar1GetMonthName(MonthNumber: Integer; var MonthName: string);
begin
  MonthName := MonthNumber.ToString + '月';
end;

{通過 OnRenderCell 事件調整更多顯示細節}
procedure TIWForm1.IWCalendar1RenderCell(ACell: TIWGridCell; const ARow, AColumn: Integer);
begin
  {讓當前選定的日期在字號上有所區別}
  if TIWCalendarCell(ACell).CellDate = TIWCalendar(ACell.Grid).SelectedDate then
    ACell.Font.Size := 14
  else
    ACell.Font.Size := ACell.Grid.Font.Size;

  {ARow = 0 是最上面一行, 也就是帶月導航的那行}
  if ARow = 0 then ACell.Font.Size := 13;
  {Arow = 1 是周標題}
  if ARow = 1 then ACell.Height := '20'; //Height 是 字符串在 Html 中不難理解
end;

{添加和日期關聯的備注信息}
procedure TIWForm1.IWButton1AsyncClick(Sender: TObject; EventParams: TStringList);
begin
  gInfoList.Values[FormatDateTime('ddmmyyyy', IWCalendar1.SelectedDate)] := IWMemo1.Text;
end;

{選擇不同日期時再取回備注信息}
procedure TIWForm1.IWCalendar1DateChange(ADate: TDateTime);
begin
  IWMemo1.Text := gInfoList.Values[FormatDateTime('ddmmyyyy', ADate)];
end;

{通過切換月份, 可以看到剛添加的與日期關聯的備注信息}
procedure TIWForm1.IWCalendar1GetDateInformation(ADate: TDateTime; VInformation: TStrings);
begin
  VInformation.Text := gInfoList.Values[FormatDateTime('ddmmyyyy', ADate)];
end;

procedure TIWForm1.IWAppFormDestroy(Sender: TObject);
begin
  gInfoList.Free;
end;


效果圖:


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved