无意中从一个免费控件源码中发现了这个方法。 其实很简单,delphi的TComponent类下面已经有一个子类TComponentEditor,只要从这个子类再继承一个类即可。
源码如下:
uses DesignIntf, DesignEditors;//新增这两个引用单元
type
TSMBLogin = class(TComponent)
private
{ Private declarations }
……
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
……
published
{ Published declarations }
property ……;
end;
type
TSmbLoginEditor = class(TComponentEditor)
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
procedure DoDesign;
end;
……
……
{ TSmbLoginEditor }
procedure TSmbLoginEditor.DoDesign;
begin
ShowGoodarkAbout;//调用自定义的编辑窗口
end;
procedure TSmbLoginEditor.ExecuteVerb(Index: Integer);
begin
//nherited;
case index of
0: DoDesign;
1: Application.MessageBox(PChar('版本1.0'), '关于', MB_OK +
MB_ICONINFORMATION);
end;
end;
function TSmbLoginEditor.GetVerb(Index: Integer): string;
begin
case index of
0: result := '设计';
1: result := '版本';
end;
end;
function TSmbLoginEditor.GetVerbCount: Integer;
begin
result := 2;
end;
编译控件后测试一下,效果图如下:
点击“设计”即可弹出自定义窗口
点击“版本”弹出对话框
效果图看这边
http://priderock.dns0755.net:800/blog/?play=show&id=107