Delphi 用ToolButton和MonthCalendar实现DateTimePicker的功能
效果图如下:

实现平台:xp xe2,其中以上功能的实现,核心主要是参考了万一老师的资料,连接:http://www.cnblogs.com/del/archive/2011/05/12/2044112.html
完整代码如下:
unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ImgList, RzButton,
Vcl.ExtCtrls, RzPanel, Vcl.StdCtrls; type
TForm1 = class(TForm)
ImageList1: TImageList;
RzToolbar1: TRzToolbar;
RzToolButton1: TRzToolButton;
MonthCalendar1: TMonthCalendar;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure RzToolButton1Click(Sender: TObject);
procedure MonthCalendar1Click(Sender: TObject);
procedure MonthCalendar1GetMonthBoldInfo(Sender: TObject; Month,
Year: Cardinal; var MonthBoldInfo: Cardinal);
private
{ Private declarations }
procedure MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer);
procedure MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer);
public
{ Public declarations }
end; var
Form1: TForm1;
yy,mm,dd: string; //存年月日
y1,m1,d1: Word; //从DecordDate函数解析年月日,然后传值给yy,mm,dd implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject);
begin
DecodeDate(MonthCalendar1.Date,y1,m1,d1);
yy := IntToStr(y1);
mm := IntToStr(m1);
dd := IntToStr(d1);
MonthCalendar1.Visible := False;
RzToolButton1.Caption := DateToStr(MonthCalendar1.Date);
//TFrom和TMonthCalendar都是由TControl的派生来的,TMonthCalendar通过TForm间接继承OnMouseUp、OnMouseDown属性
TForm1(MonthCalendar1).OnMouseUp := MouseUp;
TForm1(MonthCalendar1).OnMouseDown := MouseDown;
end; procedure TForm1.RzToolButton1Click(Sender: TObject);
begin
MonthCalendar1.Visible := not MonthCalendar1.Visible;
if MonthCalendar1.Visible then
begin
MonthCalendar1.BringToFront;
Memo1.Align := alRight;
Memo1.Width := 100;
end else Memo1.Align := alClient;
end; procedure TForm1.MonthCalendar1Click(Sender: TObject);
begin
RzToolButton1.Caption := DateToStr(MonthCalendar1.Date);
end; procedure TForm1.MonthCalendar1GetMonthBoldInfo(Sender: TObject; Month,
Year: Cardinal; var MonthBoldInfo: Cardinal);
begin
yy := Format('%u',[Year]);
RzToolButton1.Caption := yy + '-' + mm + '-' + dd;
end; procedure TForm1.MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DecodeDate(MonthCalendar1.Date,y1,m1,d1);
dd := IntToStr(d1);
if Y >= 48 then //测量所得,单击日历横线下面的区域日历隐藏
begin
MonthCalendar1.Visible := False;
Memo1.Align := alClient;
end;
end; procedure TForm1.MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer);
begin
DecodeDate(MonthCalendar1.Date,y1,m1,d1);
mm := IntToStr(m1);
//dd := IntToStr(d1);
RzToolButton1.Caption := DateToStr(MonthCalendar1.Date);
end; end.
Delphi 用ToolButton和MonthCalendar实现DateTimePicker的功能的更多相关文章
- GDI+在Delphi程序的应用 Photoshop色相饱和度明度功能
本文用GDI+实现Photoshop色相/饱和度/明度功能,参照我的其它有关GDI+在 Delphi程序的应用的文章,代码也可供TBitmap使用. 有些人不喜欢,或者不太懂Delphi的BASM代码 ...
- Delphi数据库技术中Disablecontrols和Enablecontrols的功能
一般来说,用来扫描整个数据库表并修改每个记录的某一个字段的程序如下所示: with Table Do begin DisableControls;{在修改记录的过程中,使其它部件无效} First; ...
- delphi datetimepicker 修改时间无效问题
今天用delphi写个程序,使用datetimepicker获得想要的时间.蛋疼的问题是无论怎么调整明明看着控件里面的日期变了,但是show出来的datetimepicker.datetime日期都不 ...
- delphi中DateTimePicker控件同时输入日期和时间
将DateTimePicker的Format属性中加入日期格式设成 'yyyy-MM-dd HH:mm',注意大小写 , 将kind设置为dtkTime即可,可以在每次Form onShow时将Dat ...
- DELPHI实现关闭指定进程,自身防杀
偶然翻到很久以前用DELPHI写的一个小程序,实现功能是在后台默默关闭符合条件的进程,并隐藏自身.编写目的是为了防止办公电脑运行游戏. 实现原理是: 1.程序运行后将自身以不同的名称一式三份存到系统各 ...
- Delphi XE5 常见问题解答
Delphi XE5 常见问题解答 有关于新即时试用的问题吗?请看看 RAD Studio 即时试用常见问答. 常见问题 什么是 Delphi? Embarcadero? Delphi? XE5 是易 ...
- 我常用的delphi 第三方控件
转载:http://www.cnblogs.com/xalion/archive/2012/01/09/2317246.html 有网友问我常用的控件及功能.我先大概整理一下,以后会在文章里面碰到时再 ...
- Delphi 程序结构
注:该内容整理自以下链接. http://www.cnblogs.com/hackpig/archive/2010/02/15/1668513.html 概要介绍:Object Pascal语言的结构 ...
- delphi一些小技巧 从别处看到
开发环境-------- Delphi 7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件.安装好Delphi ...
随机推荐
- cf C. Dominoes
http://codeforces.com/contest/394/problem/C 题意:有n*m个骨牌,每个骨牌上有四种样式(“01,10,11,00”),让你重新排列成一个N*M的矩阵,使2* ...
- centos6.5安装gcc6.1等c++环境
centos6.5安装gcc6.1等c++环境 1.获取gcc安装包并解压wget http://ftp.gnu.org/gnu/gcc/gcc-6.1.0/gcc-6.1.0.tar.bz2tar ...
- BZOJ 1093 [ZJOI2007]最大半连通子图
1093: [ZJOI2007]最大半连通子图 Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1986 Solved: 802[Submit][St ...
- (转载)Linux定时任务cron配置
(转载)http://blog.csdn.net/jbgtwang/article/details/7995801 实现linux定时任务有:cron.anacron.at等,这里主要介绍cron服务 ...
- 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...
- 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- HDOJ 2188 悼念512汶川大地震遇难同胞——选拔志愿者
Problem Description 对于四川同胞遭受的灾难,全国人民纷纷伸出援助之手,几乎每个省市都派出了大量的救援人员,这其中包括抢险救灾的武警部队,治疗和防疫的医护人员,以及进行心理疏导的心理 ...
- 【Android Studio】没有先安装JDK
如果没有先安装JDK,安装Android Studio的时候回出现下面这个界面: 请参考我整理的博客文章<JDK的下载.安装和配置>,链接:http://www.cnblogs.com/d ...
- POJ2286 The Rotation Game(IDA*)
The Rotation Game Time Limit: 15000MS Memory Limit: 150000K Total Submissions: 5691 Accepted: 19 ...
- IT项目经理应具备的十大软技能
现在,企业对IT部项目经理的要求越来越多.如果你认为IT项目成员只需要技术性能力,那可就错了. 据IT招聘公司调查发现,几年人们对项目管理软技能的兴趣明显浓厚起来.许多企业尽量避免把IT部门看成只是成 ...