unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyButton = class(TButton)
public
Constructor Create(AOwner: TComponent); override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TMyButton }
constructor TMyButton.Create(AOwner: TComponent);
begin
inherited;
Font.Name := '宋体';
Font.Size := 20;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with TMyButton.Create(Self) do
begin
Parent := Self;
Caption := 'asdf';
end;
end;
end.
你运行上面的例子看一看,有什么问题吗?其实 ParentFont := False 都是不必要的!