Delphi Tips Trick

For Newbie

Iklan Responsive Atas

LightBlog
Responsive Ads Here

Tuesday, 15 November 2011

Set of All Forms Font with Delphi




The trick to change the font of all forms that are in a Delphi project (dpr), without changing the properties on the Form Design. The process performed at runtime, so it would be save your time in building applications.

Declaration procedure:
FormsFont procedure (const nFont: String; szFont: Integer);
var
   i: integer;
begin
   with Application do
   begin
     for i: = 0 to ComponentCount -1 do
     begin
       if Components [i] is TForm then
       begin
         with Components [i] as TForm do
         begin
           if nFont <>''then Font.Name: = nFont;
           if szFont <> 0 then Font.size: = szFont;
           Invalidate;
         end;
       end;
     end;
   end;
end;

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
   FormsFont ('Tahoma', 8);
end;

Example implementations # 2:
TForm1.FormCreate procedure (Sender: TObject);
var
   i: Integer;
begin
   ComboBox1.Items.Clear;
   for i: = 0 to Screen.Fonts.Count - 1 do
     ComboBox1.Items.Add (Screen.Fonts.Strings [i]);
   ComboBox1.ItemIndex: = ComboBox1.Items.IndexOf (Form1.Font.Name);
   UpDown1.Position: = Form1.Font.Size;
end;

procedure TForm1.Button2Click (Sender: TObject);
begin
   FormsFont (ComboBox1.Items.Strings [ComboBox1.ItemIndex], StrToInt (Edit1.Text));
end;

TForm1.FormShow procedure (Sender: TObject);
begin
   Form2.Show;
   Form3.Show;
   Form4.Show;
end;

No comments: