月历

unit UGrid;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids,DateUtils, StdCtrls;//DateUtils
type
  TFGrid = class(TForm)
    StringGrid1: TStringGrid;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    Procedure ShowGrid();
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FGrid: TFGrid;
  TheMonth,TheYear:integer;

implementation

{$R *.dfm}

procedure TFGrid.FormCreate(Sender: TObject);
begin
  //设置串网格的列数和行数
  StringGrid1.ColCount :=8;
  StringGrid1.RowCount := 7;

  //设置串网格的第一行中的各单元中显示的字符串
  StringGrid1.Cells[1,0] :='星期一';
  StringGrid1.Cells[2,0] :='星期二';
  StringGrid1.Cells[3,0] :='星期三';
  StringGrid1.Cells[4,0] :='星期四';
  StringGrid1.Cells[5,0] :='星期五';
  StringGrid1.Cells[6,0] :='星期六';
  StringGrid1.Cells[7,0] :='星期日';

  //使程序启动时显示当月的月历
  TheYear := Yearof(date());
  TheMonth := MonthOf(date());
  Combobox1.ItemIndex := TheYear mod 2000;
  Combobox2.ItemIndex :=TheMonth-1 ;
  ShowGrid();       //刷新串网格
end;

Procedure TFGrid.ShowGrid();
var
 i,j,k,thisday:integer;  //分别表示月日的循环变量
 FirstDay:TDateTime;
 DaySum:Integer;         //月内总天数
begin
 //获取当月第一天的星期
  FirstDay :=EncodeDate(TheYear,TheMonth,1);
  j :=DayOfTheWeek(FirstDay);
  //获取当月总天数
  DaySum:=DayOfTheMonth(EndOfTheMonth(FirstDay));

  //表示要写入 StringGrid组件中的日期的当前值
  thisday :=1;
  //将各日期写入StringGrid组件中
  for i:=1 to 6 do
     for k:=1 to 7 do
       begin
         if (((i-1)*7+k)<j)  or (((i-1)*7+k)>= DaySum+j) then
           StringGrid1.Cells[k,i] :=''
         else
           begin
              if Date()= EncodeDate(TheYear,TheMonth,thisday) then
                StringGrid1.Cells[k,i] :=inttostr(thisday)+'  *Now*'
              else
                StringGrid1.Cells[k,i] :=inttostr(thisday);
              thisday :=thisday +1;
           end;
        end;
end;

procedure TFGrid.ComboBox1Change(Sender: TObject);
begin
   TheYear :=Combobox1.ItemIndex +2000;
   ShowGrid();
end;

procedure TFGrid.ComboBox2Change(Sender: TObject);
begin
  TheMonth :=Combobox2.ItemIndex+1;
  ShowGrid();
end;

end.


TLssCalendar (支持农历的月历控件) Version 1.10 发布这个控件是因为我在网上找不到支持农历的月历控件,就自己写了个,希望能有用。 您可以没有任何限制的使用、修改、分发本控件。但没有任何担保,甚至没有适合特定目的而隐含的担保。如果您修改了本控件,烦请发一份拷贝到<LuckMiky@21cn.com> 。 开发平台:PWin2000Pro + Delphi 7.0 主要功能; 1、在日历面板上同时显示公历和农历,农历部分仅支持公元1900.1.31到公元2100.12.31; 2、可以定制控件界面颜色和字体,类似TmonthCalendar,可以选择采用AAFont平滑字体边缘(有点慢); 3、控件字体大小根据控件大小自动适应; 4、支持鼠标和键盘或者代码选择日期; Home:每月的第一天 End:每月的最后一天 PageUp: 上一个月 Page:下一个月 四个方向键移动光标 5、提供了公历转农历和农历转公历函数,支持干支年、月、日;函数原形及调用方法请看代码。 本单元农历转换部分为 Mostone.Jiang 漠石(mostone@hotmail.com)的CnBase.pas,作了一点小小改动。由于控件字体过小,采用了***与月共舞工作室周劲羽***的AAFont来平滑字体显示,在此感谢2位,提供了这么好的东西给我们免费使用! Miky2004.01 更新历史: 2004-4-24 Ver 1.10 修正了网友happylife发现的Bug; 修改了Paint部分,不再使用DoubleBuffered,显示速度有很大改观; 添加了干支记日显示方式选项; 添加了keypress,keydown,keyup事件; 添加了编译指令{DEFINE AAFONT},如果你没有AAFont,请把第49行删除
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值