Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Change the font of all controls on a form at runtime Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
21-Feb-03
Category
VCL-General
Language
Delphi 2.x
Views
151
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to change the font of all controls on a form at runtime

Answer:

By default all controls have ParentFont = true, so if you did not change that for 
specific controls you could just change the forms Font property, e.g. in code 
attached to the Screen.OnActiveFormChange event. If you cannot rely on all controls 
having Parentfont = true you would have to loop over all controls on the form and 
set the font property for each or at least for those that have ParentFont set to 
false. You can use the routines from unit TypInfo for that, they allow you to 
access published properties by name. The code, again sitting in a handler for 
Screen.onActiveFormChange, would be something like this:

1   ModifyFontsFor(Screen.ActiveControl);
2   
3   //where
4   
5   procedure ModifyFontsFor(ctrl: TWinControl);
6   
7     procedure ModifyFont(ctrl: TControl);
8     var
9       f: TFont;
10    begin
11      if IsPublishedProp(ctrl, 'Parentfont') and (GetOrdProp(ctrl, 'Parentfont') =
12        Ord(false)) and IsPublishedProp(ctrl, 'font') then
13      begin
14        f := TFont(GetObjectProp(ctrl, 'font', TFont));
15        f.Name := 'Symbol';
16      end;
17    end;
18  
19  var
20    i: Integer;
21  begin
22    ModifyFont(ctrl);
23    for i := 0 to ctrl.controlcount - 1 do
24      if ctrl.controls[i] is TWinControl then
25        ModifyFontsfor(TWinControl(ctrl.controls[i]))
26      else
27        Modifyfont(ctrl.controls[i]);
28  end;


Remember to add TypInfo to your uses clause.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC