其实可以通过下面的方法实现
只不过有两个缺点:
1、要想改变Width,Height只能通过自己的函数或强制转换成基类
2、控件的大小始终都是默认大小,只能通过运行时动态改变。
unit MyEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TMyEdit = class(TEdit)
private
function GetWidth: Integer;
function GetHeight: Integer;
public
constructor Create(AOwner: TComponent); override;
procedure SetWidth(const Value: Integer);
procedure SetHeight(const Value: Integer);
published
property Height: Integer read GetHeight;
property Width: Integer read GetWidth;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Test', [TMyEdit]);
end;
{ TMyEdit }
constructor TMyEdit.Create(AOwner: TComponent);
begin
inherited;
SetWidth(250);
end;
function TMyEdit.GetHeight: Integer;
begin
Result := TEdit(Self).Height;
end;
function TMyEdit.GetWidth: Integer;
begin
Result := TEdit(Self).Width;
end;
procedure TMyEdit.SetHeight(const Value: Integer);
begin
TEdit(Self).Height := Value;
end;
procedure TMyEdit.SetWidth(const Value: Integer);
begin
TEdit(Self).Width := Value;
end;
end.