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 ...
随机推荐
- CBO学习笔记(转)
Query Transformation 在继续研究SQL的其他操作(比如Join)对CBO的影响之前,我们来讨论一下Oracle优化器的Query Transformation特性.我们都习惯于根据 ...
- C# 绘图对象 流对象 响应对象关系
- A Simple problem
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2497 题意:给出顶点数,边数及节点s,判断s是 ...
- Javascript面向对象编程(二):构造函数的继承 by 阮一峰
今天要介绍的是,对象之间的"继承"的五种方法. 比如,现在有一个"动物"对象的构造函数. function Animal(){ this.species = & ...
- javascript 路线整理
前端开发很重要,编写脚本也不容易. 总结我以前的前端学习经历,基本是一团乱麻:css+javascript是在大三自学的,当时自己做课程设计,逼着自己在一个月之内,写了一个半成品的j2ee网站.当时, ...
- POJ 3436 ACM Computer Factory
题意: 为了追求ACM比赛的公平性,所有用作ACM比赛的电脑性能是一样的,而ACM董事会专门有一条生产线来生产这样的电脑,随着比赛规模的越来越大,生产线的生产能力不能满足需要,所以说ACM董事会想 ...
- 数据结构(主席树):COGS 2211. 谈笑风生
2211. 谈笑风生 ★★★★ 输入文件:laugh.in 输出文件:laugh.out 简单对比时间限制:3 s 内存限制:512 MB [问题描述] 设T 为一棵有根树,我们做如下 ...
- 主席树:POJ2104 K-th Number (主席树模板题)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 44952 Accepted: 14951 Ca ...
- [Locked] Number of Connected Components in an Undirected Graph
Number of Connected Components in an Undirected Graph Given n nodes labeled from 0 to n - 1 and a li ...
- SRM 600(1-250pt,500pt)
DIV1 250pt 题意:给定一个vector<int>A,若能从里面选出一些数,使得他们按位或的值为x,则称x为吉利数.给定k,问最少要从A里面去掉多少个数,才能使k变为不吉利数. 解 ...