参见我的原文:
有几个朋友和同事问我怎样写控件,下面例子是派生一个Tedit;
添加一个dcs:integer的属性和一个onrightclick(鼠标右键单击)的事件;
与大家共享!
unit DcsEdit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TDcsEdit1 = class(TEdit)
private
Frightclick:TnotifyEvent;//如果你需要在事件里面带参数,参看TnotifyEvent
Fdcs:integer;
procedure getrightclickmeg(VAR Msg:TMessage);message WM_RBUTTONDOWN;//捕获鼠标右键单击消息
function reddcs:integer;
procedure setdcs(input:integer);
protected
public
constructor Create(AWoner:TComponent);override;
destructor Destroy;override;
published
property dcs:integer read reddcs write setdcs ;
property Onrightclick:TnotifyEvent read Frightclick write Frightclick;
end;
procedure Register;
implementation
constructor TDcsEdit1.Create(AWoner:TComponent);
begin
inherited Create(AWoner);
end;
function TDcsEdit1.reddcs:integer;
begin
result:=Fdcs;
end;
procedure TDcsEdit1.setdcs(input:integer);
begin
Fdcs:=input;
end;
destructor TDcsEdit1.Destroy;
begin
inherited Destroy;
end;
procedure TDcsEdit1.getrightclickmeg(VAR Msg:TMessage);
begin
if Assigned(Frightclick) then
Frightclick(self);
end;
procedure Register;
begin
RegisterComponents('Samples', [TDcsEdit1]);
end;
end.