Recent

Author Topic: How color component with the same color of form?  (Read 4557 times)

bonmario

  • Sr. Member
  • ****
  • Posts: 346
How color component with the same color of form?
« on: November 29, 2010, 10:30:08 pm »
Hi,
i have updated Lazarus at the last SVN revision.
I have a form with a ListBox. I want color the ListBox with the same Form's color. I've tried with this code but it does nothing:

Code: [Select]
procedure TForm1.FormCreate(Sender:TObject);
var OldColor, NewColor:TColor;
begin
  OldColor:=ListBox1.Color;
  ListBox1.Color:=Form1.Color;
  NewColor:=ListBox1.Color;

  if OldColor <> NewColor then begin
    ShowMessage('Ok !!!');
  end;
end;

How i can do it? It's a bug of the new implemantation of "clDefault"?

Thanks in advance, Mario

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: How color component with the same color of form?
« Reply #1 on: November 30, 2010, 08:24:31 pm »
I've found the problem. With this code is all Ok:

Code: [Select]
procedure TForm1.FormCreate(Sender:TObject);
var OldColor, NewColor:TColor;
begin
  OldColor:=ListBox1.Color;
  ListBox1.Color:=Form1.Brush.Color;
  NewColor:=ListBox1.Color;

  if OldColor <> NewColor then begin
    ShowMessage('Ok !!!');
  end;
end;


Hi, Mario

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: How color component with the same color of form?
« Reply #2 on: December 01, 2010, 11:29:30 am »
Is this on Linux?
Window$ seems to work fine.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: How color component with the same color of form?
« Reply #3 on: December 01, 2010, 12:03:20 pm »
Yes, i've used it on Linux.

This morning i've found also this that works:
Code: [Select]
ListBox1.Color:=clForm;
Hi, Mario

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How color component with the same color of form?
« Reply #4 on: December 01, 2010, 02:56:45 pm »
clDefault is default color for all wincontrols atm (0.9.29 trunk). So:
1.SomeColor := TWinControl.Brush.Color is correct,
2.MyWinControl.Color := eg. clForm is correct too (but if you want good looking control under any theme 1st statement is correct)

 

TinyPortal © 2005-2018