Application colors - Dark. lazarus / 61-Beginners ---------------------------------------------------------------------- mdalacu · 2015-08-06 11:28 I have already made an application which uses default colors for all of the controls. (dmMediaConverter) Now i want to have an option to color the whole app in dark colors (a dark theme). Does anyone know how can i achieve this the most simple way? Thanks. ---------------------------------------------------------------------- lainz · 2015-08-06 13:17 I don't know any simple way. All I know includes: - Custom Drawn Controls - BGRA-Controls - Create your own controls The first includes making your own drawing code and replace your controls. And some (or most) of these components don't work very well under desktop IMHO. The second includes to replace your controls and there are not too much you can use, according to a screenshot I seen of your application. The third is the most difficult but the one will give you more control over the whole skinning of your application. ---------------------------------------------------------------------- mdalacu · 2015-08-06 13:27 Thanks for the answer but i was thinking of something more simple, of changing controls colors (x.Color) and fonts colors the proper way. Or redefine system colors,,,ex clDefault. The problems are with setting color of a Panel the same as a TabSheet where it belongs...and controling Active/Inactive colors. Can i do this? ---------------------------------------------------------------------- Graeme · 2015-08-06 14:08 Quote from: mdalacu on August 06, 2015, 03:27:33 pmThe problems are with setting color of a Panel the same as a TabSheet where it belongs...and controling Active/Inactive colors. Can i do this? That's the problem of using LCL. They want everything to look native, and reduce the customisation that the developer can do. This caused me to move away from LCL back in 2006. I was told that if you want your LCL application to look different, change the theme of you OS!! That was out of the question. You might be able to do it if you use LCL-Qt, as Qt allows you to specify themes via the --style command line parameter, but of course then you need to implement a Qt theme using C++. My suggestion, use a toolkit that supports themes. Take a look at fpGUI Toolkit. Implementing themes are quick and easy. Themes can also be applied to the application as a whole, a specific form or a specific widget. Here are a couple of fpGUI's standard themes: [http://geldenhuys.co.uk/~graemeg/themes/].  Other users have created many more too. ---------------------------------------------------------------------- mdalacu · 2015-08-07 05:06 The reason i started this thread is that on Ubuntu with Numix theme my application looks terrible ---------------------------------------------------------------------- varianus · 2015-08-07 06:52 If using GTK2 widgetset you could try to change the theme used by your application setting the environment variable GTK2_RC_FILES Start your application with Code: [Select]GTK2_RC_FILES=/path/to/theme/gtkrc Info found here :http://crunchbang.org/forums/viewtopic.php?id=37487 ---------------------------------------------------------------------- mdalacu · 2015-08-07 10:09 Thanks, but i search for a more cross platform solution. Does anyone know how can i change the color of an diasbled button (enabled:=false) without onpaint event? Thanks. ---------------------------------------------------------------------- Blaazen · 2015-08-07 12:32 The only native buttons capable to change its color are TButton and TBitBtn and they have no OnPaint event. Buttons painted via Themes (like TSpeedBtn) cannot do it. You can do some method like this: Code: [Select]procedure EnableButton(AEnabled: Boolean; ABtn: TBitBtn);   if AEnabled then     begin       ABitBtn.Color:=clDefault;       ABitBtn.Enabled:=True;     end else     begin       ABitBtn.Color:=cl3DShadow;       ABitBtn.Enabled:=False;     end;  but it will work only if you call it directly, if you will change Parent.Enabled, it will have no effect. ---------------------------------------------------------------------- hrayon · 2015-08-07 14:08 Hi! I do not know if it helps, and shows the limitations that Mr. Graeme said. I use form inheritance, and put this code to change some colors in the parent form: Code: [Select]procedure TForm_Basic.FormCreate(Sender: TObject); var   l_integer_aux2, l_integer_aux3 : Integer;   Component : TComponent; begin   inherited;   self.Color:=StringtoColor(DataModule_Base.a_string_cor_form);   for Component in Self do   begin     if Component is TDBGrid then     begin       TDBGrid(Component).ParentColor := false;       TDBGrid(Component).AlternateColor:=StringtoColor(DataModule_Base .a_string_cor_grid_ac);       TDBGrid(Component).Color:=StringtoColor(DataModule_Base.a_string _cor_grid_col);        for l_integer_aux2 := TDBGrid(Component).Columns.Count - 1 downto 0 do        begin          if not TDBGrid(Component).Columns[l_integer_aux2].ReadOnly then            TDBGrid(Component).Columns[l_integer_aux2].Title.Color:=Str ingtoColor(DataModule_Base.a_string_cor_grid_tit)          else            TDBGrid(Component).Columns[l_integer_aux2].Title.Color:=Str ingtoColor(DataModule_Base.a_string_cor_grid_tit_readonly);        end;     end     else if (Component is TLabel) then     begin          TLabel(Component).Color:=StringtoColor(DataModule_Base.a_stri ng_cor_form);     end     else if (Component is TPageControl) then     begin       for l_integer_aux2 := TPageControl(Component).PageCount - 1 downto 0 do       begin         for l_integer_aux3 := TPageControl(Component).Pages[l_integer_aux2].ControlCount - 1 downto 0 do         begin           if (TPageControl(Component).Pages[l_integer_aux2].Controls[l _integer_aux3] is TPanel) then           begin             (TPageControl(Component).Pages[l_integer_aux2].Controls[l_ integer_aux3] as TPanel).Color:=StringtoColor(DataModule_Base.a_string_cor_form);           end;         end;       end;     end;   end; end; Later, I decided to change the colors on the fly, and put a popup menu the color swap options from the main form of the application: Code: [Select]procedure TForm_Main.pc_PaintWindows(); var   l_integer_TotalForms, l_integer_aux1 : Integer;   l_integer_aux, l_integer_aux2, l_integer_aux3 : Integer; begin   l_integer_TotalForms := screen.CustomFormCount;   for l_integer_aux1 := 0 to l_integer_TotalForms - 1 do   begin     //form     screen.CustomForms[l_integer_aux1].Color:=StringtoColor(DataModule _Base.a_string_cor_form);     for l_integer_aux := screen.CustomForms[l_integer_aux1].ComponentCount - 1 downto 0 do     begin       //ac grid       if (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] is TDBGrid) then       begin         (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TDBGrid).ParentColor := false;         (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TDBGrid).AlternateColor:=StringtoColor(DataModule_Base.a_string_cor _grid_ac);         (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TDBGrid).Color:=StringtoColor(DataModule_Base.a_string_cor_grid_col);         for l_integer_aux2 := (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TDBGrid).Columns.Count - 1 downto 0 do         begin           if not (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TDBGrid).Columns[l_integer_aux2].ReadOnly then             (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TDBGr id).Columns[l_integer_aux2].Title.Color:=StringtoColor(DataModule_Base .a_string_cor_grid_tit)           else             (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TDBGr id).Columns[l_integer_aux2].Title.Color:=StringtoColor(DataModule_Base .a_string_cor_grid_tit_readonly);         end;       end       else if (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] is TStringGrid) then       begin         (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TStringGrid).ParentColor := false;         (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TStringGrid).AlternateColor:=StringtoColor(DataModule_Base.a_string _cor_grid_ac);         (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TStringGrid).Color:=StringtoColor(DataModule_Base.a_string_cor_grid _col);          for l_integer_aux2 := (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TStringGrid).Columns.Count - 1 downto 0 do          begin            if not (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TStringGrid).Columns[l_integer_aux2].ReadOnly then              (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TStr ingGrid).Columns[l_integer_aux2].Title.Color:=StringtoColor(DataModule _Base.a_string_cor_grid_tit)            else              (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TStr ingGrid).Columns[l_integer_aux2].Title.Color:=StringtoColor(DataModule _Base.a_string_cor_grid_tit_readonly);          end;       end       else if (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] is TLabel) then       begin            (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] as TLabel).Color:=StringtoColor(DataModule_Base.a_string_cor_form);       end       else if (screen.CustomForms[l_integer_aux1].Components[l_integer_aux] is TPageControl) then       begin         for l_integer_aux2 := TPageControl(screen.CustomForms[l_intege r_aux1].Components[l_integer_aux]).PageCount - 1 downto 0 do         begin           for l_integer_aux3 := TPageControl(screen.CustomForms[l_inte ger_aux1].Components[l_integer_aux]).Pages[l_integer_aux2].ControlCoun t - 1 downto 0 do           begin             if (TPageControl(screen.CustomForms[l_integer_aux1].Compon ents[l_integer_aux]).Pages[l_integer_aux2].Controls[l_integer_aux3] is TPanel) then             begin               (TPageControl(screen.CustomForms[l_integer_aux1].Compone nts[l_integer_aux]).Pages[l_integer_aux2].Controls[l_integer_aux3] as TPanel).Color:=StringtoColor(DataModule_Base.a_string_cor_form);             end;           end;         end;       end;     end;   end; end; Probably the code should be unified to the above, to avoid duplications (I see this later - run first, optimize later). You can add more properties of components that accept change colors. See attached: (google translator) ---------------------------------------------------------------------- derek.john.evans · 2015-08-07 15:00 A more generic approach would be to iterate the components. Ive done this in the past todo language translations and to ensure all controls had the correct options setup. ie: Scrollbars, pagecontrols starting on the first tab, forms are centered, etc. I use this idea even as a sanity check to make sure I haven't forgotten to set an option in some dialog I haven't looked at in weeks. Example code: 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 ColorTheme; {$MODE DELPHI} interface uses  Forms, Graphics, StdCtrls; type  TColorTheme = class  public    ColorForm, ColorEdit: TColor;  strict private    procedure Apply(const AControl: TMemo); overload;    procedure Apply(const AControl: TEdit); overload;    procedure Apply(const AControl: TCustomForm); overload;  public    procedure InitDefault;    procedure Apply; overload;  end; var  GColorTheme: TColorTheme; implementation procedure TColorTheme.InitDefault;begin  ColorForm := clSkyBlue;  ColorEdit := clYellow;end; procedure TColorTheme.Apply(const AControl: TMemo);begin  AControl.Color := ColorEdit;end; procedure TColorTheme.Apply(const AControl: TEdit);begin  AControl.Color := ColorEdit;end; procedure TColorTheme.Apply(const AControl: TCustomForm);var  LIndex: Integer;begin  with AControl do  begin    Color := ColorForm;    for LIndex := 0 to ComponentCount - 1 do    begin      if Components[LIndex] is TEdit then      begin        Apply(TEdit(Components[LIndex]));      end else if Components[LIndex] is TMemo then      begin        Apply(TMemo(Components[LIndex]));    end;    end;  end;end; procedure TColorTheme.Apply;var  LIndex: Integer;begin  with Screen do  begin    for LIndex := 0 to CustomFormCount - 1 do    begin      Apply(CustomForms[LIndex]);    end;  end;end; initialization   GColorTheme := TColorTheme.Create;  GColorTheme.InitDefault; end. I use this kinda stuff for auto label generation as well, because I HATE labeling controls. This is the code from Geep Jeez. I call J2C_WinControlCreateLabels(Self) in OnShow for a dialog. Labels are grabbed from controls which have hint strings, and showhint is false. The hint can also be multi lined. The first line will be used for the label, the rest will be used for the hint of the control. 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 function J2C_ControlCreateLabel(const AControl: TControl): TPanel;var  LIndex: Integer;  LCaption, LHint: String;  LRect, LUnion: TRect;begin  Result := nil;  LHint := Trim(AControl.Hint);  if not AControl.ShowHint and (LHint <> EmptyStr) then  begin    AControl.ShowHint := True;    LRect := Rect(0, AControl.Top, AControl.Left, AControl.BoundsRect.Bottom);  for LIndex := 0 to AControl.Parent.ControlCount - 1 do    begin      LUnion := Bounds(0, 0, 0, 0);      if IntersectRect(LUnion, LRect, AControl.Parent.Controls[LIndex].BoundsRect) then      begin        LRect.Left := LUnion.Right;      end;    end;    if not IsRectEmpty(LRect) then    begin      LIndex := Pos(#10, LHint);      if LIndex > 0 then      begin        LCaption := Trim(Copy(LHint, 1, LIndex - 1));        LHint := Trim(Copy(LHint, LIndex + 1, MaxInt));    end else begin        LCaption := LHint;      end;      AControl.Hint := LHint;      if not GPlatform.IsWindows9x then      begin        AControl.Color := clInfoBlock;      end;      Result := TPanel.Create(AControl);      Result.BoundsRect := LRect;      Result.BorderWidth := 6;      Result.Alignment := taRightJustify;    Result.BevelOuter := bvNone;      Result.Caption := LCaption;      Result.Hint := LHint;      Result.ShowHint := True;      Result.Cursor := crHelp;      Result.Parent := AControl.Parent;      Result.Font.Color := clBlack;    end;  end;end; procedure J2C_WinControlCreateLabels(const AWinControl: TWinControl);var  LIndex: Integer;begin  if (AWinControl is TCustomEdit) or (AWinControl is TDirectoryEdit) or    (AWinControl is TCustomComboBox) then  begin    J2C_ControlCreateLabel(AWinControl);  end;  for LIndex := 0 to AWinControl.ControlCount - 1 do  begin    if AWinControl.Controls[LIndex] is TWinControl then    begin      J2C_Win ControlCreateLabels(TWinControl(AWinControl.Controls[LIndex]));    end;  end;end; EDIT: O, yeay. I also use it for saving/loading control settings to a inifile. Im sure there is a better way, but I seem to alway use the same idea. The code is a little long, and off topic.