随便定义了一个新控件TMyLabel(从TLabel继承).并定义了一个控件编辑器,双击控件可以编辑Caption属性
//D6下通过
//MyLabel
unit MyLabel;
interface
uses
Windows, Messages, SysUtils, Classes,
Controls, StdCtrls, Forms;
type
TMyLabel = class(TLabel);
procedure Register;
implementation
uses
DesignEditors, DesignIntf,
MyLabelForm;
type
TMyLabelEditor = class(TComponentEditor)
public
procedure Edit; override;
end;
{ TMyLabelEditor }
procedure TMyLabelEditor.Edit;
var
Lbl: TMyLabel;
begin
with TfrmMyLabel.Create(Application) do
try
Lbl := GetComponent as TMyLabel;
memCaption.Lines.Text := Lbl.Caption;
if ShowModal = mrOk then
Lbl.Caption := memCaption.Lines.Text;
finally
Free;
end;
end;
procedure Register;
begin
RegisterComponents('Samples', [TMyLabel]);
RegisterComponentEditor(TMyLabel, TMyLabelEditor);
end;
end.
//MyLabelForm.dfm
object frmMyLabel: TfrmMyLabel
Left = 226
Top = 77
BorderStyle = bsDialog
Caption = 'My Label Editor'
ClientHeight = 249
ClientWidth = 479
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 12
object memCaption: TMemo
Left = 0
Top = 0
Width = 479
Height = 201
Align = alTop
ScrollBars = ssBoth
TabOrder = 0
end
object btnOk: TButton
Left = 304
Top = 216
Width = 75
Height = 25
Caption = '确定(&O)'
ModalResult = 1
TabOrder = 1
end
object btnClose: TButton
Left = 392
Top = 216
Width = 75
Height = 25
Caption = '关闭(&C)'
ModalResult = 2
TabOrder = 2
end
end
//MyLabelForm
unit MyLabelForm;
interface
uses
Windows, Messages, SysUtils, Variants,
Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TfrmMyLabel = class(TForm)
memCaption: TMemo;
btnOk: TButton;
btnClose: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.