S
samuelzhu
Unregistered / Unconfirmed
GUEST, unregistred user!
//目的是设置自定义控件中的Tlistview控件中的字体, 但调用该自定义控件只能在
//设计模式下可行,而运行应用程序时对字体的设置无效.
源程序如下:
unit test;
interface
uses
Windows, Messages, Classes, Graphics, ComCtrls, Controls,
StdCtrls, ExtCtrls;
type
Ttest = class(TcustomControl)
private
ListView1: TListView;
//其它控件;
fFont:Tfont;
protected
procedure Paint; override;
procedure Setfont(value:Tfont);
public
Constructor Create(Aowner: Tcomponent); Override;
Destructor Destroy; Override;
published
property myFont:Tfont read fFont write Setfont;
end;
procedure Register;
implementation
Constructor Ttest.Create(Aowner: Tcomponent);
begin
Inherited Create(Aowner);
fFont:=Tfont.Create ;
ListView1:=Tlistview.Create(self);
with ListView1 do begin
Parent :=self;
height:=150;
Columns.Add;
end;
end;
procedure Ttest.Paint;
var ListItem: TListItem;
begin
inherited Paint;
with ListView1 do begin
ListItem := Items.Add;
Listitem.Caption :='test';
end;
end;
Destructor Ttest.Destroy;
Begin
ListView1.Free ;
ffont.Free;
Inherited Destroy;
End;
procedure Ttest.Setfont(value:Tfont);
begin
listview1.Font.assign(value);
end;
procedure Register;
begin
RegisterComponents('Samples', [Ttest]);
end;
end.
//设计模式下可行,而运行应用程序时对字体的设置无效.
源程序如下:
unit test;
interface
uses
Windows, Messages, Classes, Graphics, ComCtrls, Controls,
StdCtrls, ExtCtrls;
type
Ttest = class(TcustomControl)
private
ListView1: TListView;
//其它控件;
fFont:Tfont;
protected
procedure Paint; override;
procedure Setfont(value:Tfont);
public
Constructor Create(Aowner: Tcomponent); Override;
Destructor Destroy; Override;
published
property myFont:Tfont read fFont write Setfont;
end;
procedure Register;
implementation
Constructor Ttest.Create(Aowner: Tcomponent);
begin
Inherited Create(Aowner);
fFont:=Tfont.Create ;
ListView1:=Tlistview.Create(self);
with ListView1 do begin
Parent :=self;
height:=150;
Columns.Add;
end;
end;
procedure Ttest.Paint;
var ListItem: TListItem;
begin
inherited Paint;
with ListView1 do begin
ListItem := Items.Add;
Listitem.Caption :='test';
end;
end;
Destructor Ttest.Destroy;
Begin
ListView1.Free ;
ffont.Free;
Inherited Destroy;
End;
procedure Ttest.Setfont(value:Tfont);
begin
listview1.Font.assign(value);
end;
procedure Register;
begin
RegisterComponents('Samples', [Ttest]);
end;
end.