Pagecontrol - Panels - style lazarus / 31-LCL ---------------------------------------------------------------------- Nicole · 2022-09-30 06:47 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 PageControl_Main.Font.Color:=myDarkColor; sets all fonts of my TSpeedButtons in all TabSheets of my TPageControl to myDarkColor. Is there a way to set the fonts of all TPanels, TStatic text etc the same way? The idea is: Change all the styles of my TPageContol on one place. ---------------------------------------------------------------------- Gald · 2022-09-30 07:02 You can use a for loop for each component, TSpeedButton, TPanel, TStaticText, etc. ---------------------------------------------------------------------- Nicole · 2022-09-30 08:11 thank you. Can you kindly provide an example how this may look? ---------------------------------------------------------------------- wp · 2022-09-30 12:26 Be warned when attempting to change colors: Since many LCL controls are drawn by the widgetset (=OS) you have little control over colors - for some controls it works, for others it does not. If you want complete control over colors you must use a third-party, owner-drawn collection of controls. There are some libs in OPM, but I have never seen a collection with is as complete as the built-in LCL controls (but I did not look too carefully). My advice: Leave colors alone, and let the widgetset do its work. This way you get a consistent look of your application. If you want dark mode, switch your OS to dark mode and you will get it for free (Unfortunately the dark mode of windows even in Win 11 22H2 is still kind of mysterious for standard GUI applications = not working). ---------------------------------------------------------------------- Nicole · 2022-09-30 13:34 Hm, is there no way out? Not sure, if this works in recent Delphi version like this anymore. I attach you a screenshot. This was what I used since long: I did not care for any color with it. Suddenly the topic is back again. Is there nothing comparable in Lazarus? It is really nice and gives the programmer time for more important issues. ---------------------------------------------------------------------- KodeZwerg · 2022-09-30 13:40 I do not know if I understand you correct, but you could (from my point of view) : a) setup your main form and let created controls grab main forms setup b) iterate over all components and setup whatever you want to set up for b) you could do things 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 procedure TFormName.DoSomethingSpecial;var  i: Integer;begin  for i := Pred(Self.ComponentCount ) downto 0 do    begin      try        Self.Components[i].Font := ...FontVariable...      except      end;  end;end; ---------------------------------------------------------------------- wp · 2022-09-30 14:04 Quote from: Nicole on September 30, 2022, 03:34:36 pmHm, is there no way out? Not sure, if this works in recent Delphi version like this anymore. I attach you a screenshot. This was what I used since long: I did not care for any color with it. Suddenly the topic is back again. Is there nothing comparable in Lazarus? It is really nice and gives the programmer time for more important issues. What you see here is FireMonkey, a component library in addition to Delphi's VCL with its own controls. Lazarus does not have an equivalent. Well, not exactly: there is the Customdrawn widgetset, which you can select in the project options > Additions and overrides > Select widgetset (maybe you must also install the package "customdrawn", https://wiki.freepascal.org/Lazarus_Custom_Drawn_Controls) - but this is unmaintained half-finished work and I never was able to create something useful with it. As I said, you must look for a third-party library which draws the controls without the widgetset (BGRA, for example) and you must use these controls in your application and hope that all the controls that you need are supported. When it is only a few components that you want to "re-color" you might also look at the ExCtrls library on CCR which tries to mimic the original LCL controls, but in a way that some restrictions due to the widgetset are by-passed (https://wiki.lazarus.freepascal.org/ExCtrls). To be honest - this is also unfinished work, but at least maintained (by myself). ---------------------------------------------------------------------- Nicole · 2022-09-30 14:22 Thank you for your answers. @KodeZwerg: Components.Font does not work for me @wp I like the look of ExCtrls much. The more I look at it, the more I like it. But not sure, if I shall take more complexity into my project. I'll think it over. ---------------------------------------------------------------------- KodeZwerg · 2022-09-30 14:28 Quote from: Nicole on September 30, 2022, 04:22:05 pm@KodeZwerg: Components.Font does not work for meI love that kind of error report... "does not work".... good. ---------------------------------------------------------------------- Nicole · 2022-09-30 14:53 I cannot combine component with font, see attach. If I enforce it, there is an error-message. ---------------------------------------------------------------------- wp · 2022-09-30 15:07 The loop in KodeZwerg's code iterates through the elements of a form considering them in the light of their most elemental class, TComponent - every class that is added to a TForm must be a TComponent at least, and the Components[] "array" lists them. Each element of Components was created as a higher class, though,  and you can access the properties of the higher class by type-casting the Components[] to that higher class. TControl descends from TComponent and is the first class which has a font. Therefore, you at first must check whether the current component is a TControl and then you can access its Font by considering TControl(Components[]). 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 TFormName.DoSomethingSpecial;    var      i: Integer;    begin      for i := 0 to Pred(ComponentCount) do        if Components[i] is TControl then          TControl(Components[i]).Font.Style := [fsBold];    end; ---------------------------------------------------------------------- KodeZwerg · 2022-09-30 15:07 Quote from: Nicole on September 30, 2022, 04:53:26 pmI cannot combine component with font, see attach. If I enforce it, there is an error-message.My bad, here is a quick fix 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 TForm1.FormCreate(Sender: TObject);var  i: Integer;  LFont: TFont;begin  LFont := TFont.Create;  try    LFont.Name := 'Arial';    LFont.Color := clGreen;    LFont.Size := 11;    for i := 0 to Pred(Self.ComponentCount) do      begin        try          TControl(Self.Components[i]).Font := LFont;        except        end;      end;  finally    LFont.Free;  end;end; ---------------------------------------------------------------------- Nicole · 2022-09-30 15:46 MUST it be on create? I made a method from it and get: 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 [Window Title]Fehler [Content]Projekt project_T hat Exception-Klasse »External: ACCESS VIOLATION« ausgelöst mit der Meldung:Access violation reading from address $FFFFFFFFFFFFFFFF.  In Datei 'control.inc' in Zeile 3460:if FFont.IsEqual(Value) then exit; [Ok] it is this line 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 TControl(Self.Components[i]).Font := LFont; ---------------------------------------------------------------------- Nicole · 2022-09-30 16:06 @Werner, thank you for the code. The loop works fine. Unfortunately (in my case) it does "the same" as 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  PageControl_Main.Font.Color:=AColor; What I have at the moment are these lines 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    For i:=0 to PageControl_Main.PageCount - 1 do     PageControl_Main.Pages[i].Color:=DarkRedColor;    PageControl_Main.Font.Color:=DarkRedColor; Those lines color the TFrames and TSpeedButtons nicely (see screenshot with the Button). My problem are (see screenshot as well): RadioBoxes and Checkboxes. I attach you a screenshot with the radiobox: The font stay black and are hardly readably. Do I set the background to a brighter color, then the label stays darkRed with black fonts, - hardly readably. I want the red style and white fonts, like the lines, which "jump" to white. So the screenshot shows you: One "wanted" speedbutton and two "not wanted" RadioBoxes ---------------------------------------------------------------------- KodeZwerg · 2022-09-30 16:21 Quote from: Nicole on September 30, 2022, 05:46:56 pmMUST it be on create? I made a method from it and get: 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 [Window Title]Fehler [Content]Projekt project_T hat Exception-Klasse »External: ACCESS VIOLATION« ausgelöst mit der Meldung:Access violation reading from address $FFFFFFFFFFFFFFFF.  In Datei 'control.inc' in Zeile 3460:if FFont.IsEqual(Value) then exit; [Ok] it is this line 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 TControl(Self.Components[i]).Font := LFont; Since I do not know how or where you initialize LFont, another example. Full working source: 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    Panel1: TPanel;    Panel2: TPanel;    procedure Button1Click(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure FormCreate(Sender: TObject);  private    FFont: TFont;    procedure ApplyFonts;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  FFont := nil;end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  if FFont <> nil then    FFont.Free;  CloseAction := caFree;end; procedure TForm1.Button1Click(Sender: TObject);begin  ApplyFonts;end; procedure TForm1.ApplyFonts;var  i: Integer;begin  if FFont = nil then    FFont := TFont.Create;  try    FFont.Name := 'Arial';    FFont.Color := clGreen;    FFont.Size := 11;    for i := 0 to Pred(Self.ComponentCount) do      begin        try          TControl(Self.Components[i]).Font := FFont;        except        end;      end;  finally  end;end; end.Watch carefully where I do what. It does not matter how you do aslong as it is in a straightforward way. ---------------------------------------------------------------------- wp · 2022-09-30 16:25 As I wrote above, this is not possible with the standard LCL TRadioButtons. The same as in Delphi's VCL, BTW. Basically this should be documented on page Restrictions of the object inspector (or in the Restriction Browser in menu View), but I would not swear that these entries are up-to-date. ---------------------------------------------------------------------- Lulu · 2022-09-30 19:59 Hi, to customize font's color on TCheckBox and TRadioButton, I do the following: Set an empty caption on radio button or check boxAdd a TLabel with the appropriate caption and anchor it to the right of the radio button or check boxFor a radio button: in TLabel.OnClick event, set the Checked radio button property to TRUEFor a checkbox: in TLabel.OnClick event, toogle the state of Checked propertyYou can then modify the font color of the TLabel as your needs. Attached a simple project to demonstrate. ---------------------------------------------------------------------- KodeZwerg · 2022-10-01 09:39 Quote from: Lulu on September 30, 2022, 09:59:14 pmHi, to customize font's color on TCheckBox and TRadioButton, I do the following:When I would do that, I would SubClass and OwnerDraw. My own try for a full working Windows DarkTheme support (created in Delphi not FPC!) is available here https://www.delphipraxis.net/207862-kodezwergs-real-theme- beispiel.html It actually really react on OS changes for that matter but my own try looks not that pretty like if you would use Styles. ---------------------------------------------------------------------- KodeZwerg · 2022-10-01 13:19 Quote from: wp on September 30, 2022, 06:25:48 pmAs I wrote above, this is not possible with the standard LCL TRadioButtons. The same as in Delphi's VCL, BTW. Basically this should be documented on page Restrictions of the object inspector (or in the Restriction Browser in menu View), but I would not swear that these entries are up-to-date. No. I proof it with images. ---------------------------------------------------------------------- VisualLab · 2022-10-01 13:24 Hmm... Maybe it would be easier and safer: 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 TForm1.ApplyFonts;var  i: Integer;begin  if FFont = nil   then FFont := TFont.Create;  try    FFont.Name := 'Arial';    FFont.Color := clGreen;    FFont.Size := 11;    for i := 0 to Pred(Self.ControlCount) do      begin        try          TControl(Self.Controls[i]).Font := FFont;        except        end;      end;  finally  end;end;  As it concerns the program window (TForm), it has a list of controls (Controls property) and their quantity (ControlCount property). It inherits them from the TWinControl class. ---------------------------------------------------------------------- wp · 2022-10-01 13:39 Quote from: KodeZwerg on October 01, 2022, 03:19:42 pmQuote from: wp on September 30, 2022, 06:25:48 pmAs I wrote above, this is not possible with the standard LCL TRadioButtons. The same as in Delphi's VCL, BTW. Basically this should be documented on page Restrictions of the object inspector (or in the Restriction Browser in menu View), but I would not swear that these entries are up-to-date. No. I proof it with images. Well, you turn off theme-services, and if you do this it works out of the box: Just set TRadioButton.Color and TRadioButton.Font.Color in the Object Inspector. Since the OI runs WITH theme services you do not get a visual feedback, but when the program runs the background and text colors have taken the corresponding values. Of course, only without theme-services. This results in the Win95 look. If you like that - fine; if you don't the same problem again. ---------------------------------------------------------------------- KodeZwerg · 2022-10-01 14:01 @wp: I do agree your current post but not the post where you said it is not possible. That without themes it works out of box i do know, my method is just a general helper without need to type "radiobutton1.color, radiobutton1.font.color etc..." i can throw in whatever control and it works "out-of-box" ) ---------------------------------------------------------------------- Nicole · 2022-10-03 07:14 I installed BGRAD in the meanwhil and tried it, - and to sum it up: I will uninstall it. There seems to be no RadioBox,  demos I cannot find. ExCtrls is downloading at the moment for the next try. PS  - done- Thank you KodeZwerg. I solved it by exctrl and thank all others for the answers as well!