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 ...
随机推荐
- ios开发学习--歌词处理--解析lrc文件
我觉得要想解析lrc 首先大家应该了解一下lrc文件的结构,大家可以去看一下**百科 我这里粗略的写一下: ■ 时间标签(Time-tag) 形式为"[mm:ss]"(分钟数:秒数 ...
- Spring MVC控制器用@ResponseBody声明返回json数据报406的问题
本打算今天早点下班,结果下午测试调试程序发现一个问题纠结到晚上才解决,现在写一篇博客来总结下. 是这样的,本人在Spring mvc控制层用到了@ResponseBody标注,以便返回的数据为json ...
- TOP命令解析
转自: http://www.cnblogs.com/yjf512/ 你不一定懂的cpu显示信息 2013-10-23 11:48 by 轩脉刃, 1688 阅读, 0 评论, 收藏, 编辑 在使用t ...
- Maven实战六
转载:http://www.iteye.com/topic/1132509 一.简介 settings.xml对于maven来说相当于全局性的配置,用于所有的项目,当Maven运行过程中的各种配置,例 ...
- struts2的action访问servlet API的三种方法
学IT技术,就是要学习... 今天无聊看看struts2,发现struts2的action访问servlet API的三种方法: 1.Struts2提供的ActionContext类 Object g ...
- vijos1053Easy sssp
P1053Easy sssp 描述 输入数据给出一个有N(2 <= N <= 1,000)个节点,M(M <= 100,000)条边的带权有向图. 要求你写一个程序, 判断这个有向图 ...
- FFT(快速傅立叶变换):HDU 1402 A * B Problem Plus
Calculate A * B. Input Each line will contain two integers A and B. Process to end of file. Note: th ...
- 【模拟】CSU 1807 最长上升子序列~ (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1807 题目大意: 给你一个长度为N(N<=105)的数列,数列中的0可以被其他数 ...
- 开源的asp.net工作流程引擎。 http://ccflow.org
开源的asp.net工作流程引擎. http://ccflow.org
- a为整型数组,&a+1的含义
#include <stdio.h> int main() { int a[10]; printf("a的值为:\t%d\n",a); printf("&am ...