uses TypInfo; {$R *.dfm}function TForm1.SetCtrlFont(ctrl: TComponent): boolean; var pi : PPropInfo; AFont: TFont; begin result := false; pi := getPropInfo(pTypeInfo(ctrl.ClassInfo ), 'Font' ); if ( pi <> nil ) then begin AFont := TFont.Create; AFont.Style := [fsBold]; SetOrdProp(ctrl, pi, Longint(AFont)); AFont.Free; result := true; end; end;procedure TForm1.Button1Click(Sender: TObject); var I: integer; begin for I:=0 to self.ComponentCount-1 do begin SetCtrlFont(self.Components[i]); end; end;
Form的Font.size设为9
Form的Font.size设为9
==================================
这是所谓的难问题……
{$R *.dfm}function TForm1.SetCtrlFont(ctrl: TComponent): boolean;
var
pi : PPropInfo; AFont: TFont;
begin
result := false;
pi := getPropInfo(pTypeInfo(ctrl.ClassInfo ), 'Font' );
if ( pi <> nil ) then
begin
AFont := TFont.Create;
AFont.Style := [fsBold];
SetOrdProp(ctrl, pi, Longint(AFont));
AFont.Free;
result := true;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var I: integer;
begin
for I:=0 to self.ComponentCount-1 do
begin
SetCtrlFont(self.Components[i]);
end;
end;
1.设计的时候,可能不是所有的控件的ParentFont属性设为true;
2.要求的运行中动态改变.
3.有可能改为9, 也可能改为12, 则所以控件都变 12
我试试!谢谢