给你代码,我用TEdit做例子写给你!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyXEdit=Class(TEdit)
procedure CMEXIT(var Message: TCMGotFocus); message CM_EXIT;
end;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
newedit:TMYXEdit;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMyXEdit }
procedure TMyXEdit.CMEXIT(var Message: TCMGotFocus);
var
dc:HWnd;
begin
HideSelection:=false;
dc:=getdc(Handle);
SetTextColor(dc, clBlack);
TextOut(dc,0,0,pchar(DateToStr(Date)),length(DateToStr(Date)));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
newedit:=TMYXEdit.Create(self);
newedit.Parent:=self;
newedit.Left:=200;
newedit.top:=200;
end;
end.