Change Fonts via Code [SOLVED] lazarus / 21-General ---------------------------------------------------------------------- AlphaInc. · 2021-04-09 06:45 Hello everybody, As part of my fine tuning I want to set a custom font (including font size, making it bold, etc.) for a few buttons. In the past I did this through the Lazarus GUI. Therefore I wanted to know, if it's possible to set the font and font size via code? I already set up a procedure, which runs at startup of my tool, which sets background picture and another image. This is said procedure, where I wanted to add a global font: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure T Form1.ui();begin TImage1.LoadFromFile(picture1.jpg); TImage2.LoadFromF ile(picture2.jpg);end; ---------------------------------------------------------------------- lucamar · 2021-04-09 10:18 Quote from: AlphaInc. on April 09, 2021, 08:45:05 amTherefore I wanted to know, if it's possible to set the font and font size via code? Any property that you can set in the designer you can also set by code; in your case something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SomeButton.Font.Name := 'Dejavu Sans';SomeButton.Font.Size := 12; ---------------------------------------------------------------------- AlphaInc. · 2021-04-09 11:01 Thank you for your replay. Is it possible to do this for all buttons at once? Thought about something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i EveryButton.Font.Name := 'Arial';EveryButton.Font.Size := 12; Just to make an example ---------------------------------------------------------------------- dseligo · 2021-04-09 11:13 Quote from: AlphaInc. on April 09, 2021, 01:01:31 pmThank you for your replay. Is it possible to do this for all buttons at once? Thought about something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i EveryButton.Font.Name := 'Arial';EveryButton.Font.Size := 12; Just to make an example Try this (Form1 is your form name): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  i: Integer;begin  For i:=0 to Form1.ComponentCount-1 do    If Components[i] is TButton then    begin      (Form1.Components[i] as TButton).Font.Name:='Arial';      (Form1.Components[i] as TButton).Font.Size:=12;    end;end; ---------------------------------------------------------------------- AlphaInc. · 2021-04-09 11:23 Quote from: dseligo on April 09, 2021, 01:13:38 pmQuote from: AlphaInc. on April 09, 2021, 01:01:31 pmThank you for your replay. Is it possible to do this for all buttons at once? Thought about something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i EveryButton.Font.Name := 'Arial';EveryButton.Font.Size := 12; Just to make an example Try this (Form1 is your form name): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  i: Integer;begin  For i:=0 to Form1.ComponentCount-1 do    If Components[i] is TButton then    begin      (Form1.Components[i] as TButton).Font.Name:='Arial';      (Form1.Components[i] as TButton).Font.Size:=12;    end;end;  This worke perfectly. Thank you very much. ---------------------------------------------------------------------- Handoko · 2021-04-09 15:46 You can use ParentFont property. As long as it is set to True, the control will automatically change the font when its parent's font changed. You can make a quick test: Drop some components to the form. Select the form and change its font. All the component's font will be changed.