效果图如下:

实现平台: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的功能的更多相关文章

  1. GDI+在Delphi程序的应用 Photoshop色相饱和度明度功能

    本文用GDI+实现Photoshop色相/饱和度/明度功能,参照我的其它有关GDI+在 Delphi程序的应用的文章,代码也可供TBitmap使用. 有些人不喜欢,或者不太懂Delphi的BASM代码 ...

  2. Delphi数据库技术中Disablecontrols和Enablecontrols的功能

    一般来说,用来扫描整个数据库表并修改每个记录的某一个字段的程序如下所示: with Table Do begin DisableControls;{在修改记录的过程中,使其它部件无效} First; ...

  3. delphi datetimepicker 修改时间无效问题

    今天用delphi写个程序,使用datetimepicker获得想要的时间.蛋疼的问题是无论怎么调整明明看着控件里面的日期变了,但是show出来的datetimepicker.datetime日期都不 ...

  4. delphi中DateTimePicker控件同时输入日期和时间

    将DateTimePicker的Format属性中加入日期格式设成 'yyyy-MM-dd HH:mm',注意大小写 , 将kind设置为dtkTime即可,可以在每次Form onShow时将Dat ...

  5. DELPHI实现关闭指定进程,自身防杀

    偶然翻到很久以前用DELPHI写的一个小程序,实现功能是在后台默默关闭符合条件的进程,并隐藏自身.编写目的是为了防止办公电脑运行游戏. 实现原理是: 1.程序运行后将自身以不同的名称一式三份存到系统各 ...

  6. Delphi XE5 常见问题解答

    Delphi XE5 常见问题解答 有关于新即时试用的问题吗?请看看 RAD Studio 即时试用常见问答. 常见问题 什么是 Delphi? Embarcadero? Delphi? XE5 是易 ...

  7. 我常用的delphi 第三方控件

    转载:http://www.cnblogs.com/xalion/archive/2012/01/09/2317246.html 有网友问我常用的控件及功能.我先大概整理一下,以后会在文章里面碰到时再 ...

  8. Delphi 程序结构

    注:该内容整理自以下链接. http://www.cnblogs.com/hackpig/archive/2010/02/15/1668513.html 概要介绍:Object Pascal语言的结构 ...

  9. delphi一些小技巧 从别处看到

    开发环境--------    Delphi 7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件.安装好Delphi ...

随机推荐

  1. Android Wear开发 - 数据通讯 - 第二节 : 数据的发送与接收

    本节由介绍3种数据的发送接收:1.Data Items : 比特类型数据,限制100KB以内2.Assets : 资源类型数据,大小无上限3.Message : 发送消息,触发指令 http://de ...

  2. Struts2+JFreeChart

    前言 关于Struts2入门以及提高等在这里就不介绍了,但是关于Struts2的学习有以下推荐: struts2-showcase-2.0.6.war:这个是官方自带的Demo(struts-2.0. ...

  3. sphinx插入css

    使用role指令达到目的. We can put following lines at the beginning of our RST file to specify its style. .. r ...

  4. 【HDOJ】4704 Sum

    数学题.f(n) = 2^(n-1) mod (1e9+7). #include <cstdio> #define MAXN 100005 char buf[MAXN]; __int64 ...

  5. Cent OS 命令行和窗口界面默认登录切换方法

    在 CentOS 中的修改方法如下: 1. root登陆,免得老是sudo 2. 打开/etc/inittab 文件     #vim /etc/inittab 3. 在默认的 run level 设 ...

  6. 5451 HDU Best Solver

    链接: Best Solver 题目分析: 这个题目的关键点是需知道“共轭”. 如 :(A√B + C√D)  和 (A√B - C√D) 是共轭的 这个有一个规律 (A√B + C√D)^n + ( ...

  7. 【最短路】FOJ 2243 Daxia like uber

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2243 题目大意: 给一张N个点M条边的有向图,从s出发,把在x1的人送到y1,在x2的人送到y2用的最短距离 ...

  8. 高效算法——B 抄书 copying books,uva714

    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description ...

  9. linux内网机器访问外网代理设置squid

    公司一般出于安全考虑, 在同一局域网中只有一台机器可以访问外网,运维进行了整体的限制, 但是在后面的工作中,需要在机器上安装一些软件,及命令,所以其他的机器需要访问外网来简化工作, 但又不能打乱原有运 ...

  10. ural 1136. Parliament

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1136 题目描述:给定一个按照(左子树-右子树-根)(即先序)遍历序列的树,求其按照 右子 ...