请各位帮忙(100分)

  • 主题发起人 主题发起人 arm
  • 开始时间 开始时间
What r u want to say?
 
你的问题也太深奥了吧?
深奥的都看不见了...
 

我有如下代码,我想将我的控件拥有ONKEYPRESS 、
ONEXIT 两个事件
但是我的代码总是不好市,这两个事件总是没有反映

代码如下,请各位帮小弟更正


unit labedit;

interface

uses
Windows, Messages, stdctrls,SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
tlabedit = class(twincontrol)
private
fedit:tedit;
flab:tlabel;
fexit:tnotifyevent;
fkey:TKeyPressEvent;
function getcaption: string;
function gettext: string;
procedure settext(const Value: string);
procedure setcaption(const Value: string);
procedure wmsize(var message:tmessage) ;message wm_size;
procedure cmfontchanged(var message :Tmessage);message CM_fontchanged;
protected

public
constructor create(aowner:tcomponent);override;
destructor destory;
published
property text:string read gettext write settext;
property caption :string read getcaption write setcaption;
property onexit read fexit write fexit;
property onkeypress read fkey write fkey;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('standard', [tlabedit]);
end;

{ tlabedit }

procedure tlabedit.cmfontchanged(var message: Tmessage);
begin
inherited;
end;

constructor tlabedit.create(aowner: tcomponent);
begin
inherited create(aowner);
width:=200;
height:=25;
flab:=tlabel.Create(self);
flab.Font.Name:='宋体';
flab.Font.Size:=12;
flab.Parent:=self;
flab.Left:=left;
flab.Width:=75;
flab.height:=25;
flab.Visible:=true;
fedit:=tedit.Create(self);
fedit.Parent:=self;
fedit.Left:=left+flab.Width+5;
fedit.Width:=width-5-flab.Width;
fedit.height:=25;
fedit.Font.Name:='宋体';
fedit.Font.Size:=10;
fedit.Visible:=true;
fedit.OnKeyPress:=fkey;
fedit.OnExit:=fexit;
end;

destructor tlabedit.destory;
begin
flab.free;
fedit.Free;
inherited;
end;

function tlabedit.getcaption: string;
begin
result:=flab.Caption;
end;

function tlabedit.gettext: string;
begin
result:=fedit.Text;
end;

procedure tlabedit.setcaption(const Value: string);
begin
flab.Caption:=value;
end;

procedure tlabedit.settext(const Value: string);
begin
fedit.Text:=value;
end;

procedure tlabedit.wmsize(var message: tmessage);
begin
inherited;
flab.height:=height;
fedit.Width:=height;
fedit.Width:=width-flab.Width-5;
end;

end.
 
试试:
将控件所在的Form.KeyPreview:=True;
 
哇!这问题好!无字天书啊!
 
GIVE YOU A SOURCE OF LABEDIT
CAN SOULVE YOUR QUSTION
 
接受答案了.
 
后退
顶部