0

In my program (Chess) i need to generate a lot of Tpanels with a specific background color(black or white). Tpanels are created, but, despite setting the color, they remain colorless.

for i := 1 to 8 do
  for j := 1 to 8 do
  begin
    CellArray[i,j]:= TPanel.Create(Chess);
    CellArray[i,j].Parent := Chess;
    CellArray[i,j].Left := 20+(i-1)*70;
    CellArray[i,j].Top := 20+(j-1)*70;
    CellArray[i,j].Width := 70;
    CellArray[i,j].Height := 70;
    CellArray[i,j].Tag := i*10+j;
    if odd(i+j) then 
      CellArray[i,j].Color := clblack
    else 
      CellArray[i,j].Color := clwhite;
  end;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • So, you need to set the panel's `ParentBackground` property to `False`. However, I would caution you that building a chess board from panels, and presumably using lots of `TImage` controls for the pieces, is a sure fire way to go crazy. Use a paint box and paint the board yourself. Using components to represent squares and pieces is just way too messy. – David Heffernan Jan 22 '16 at 16:13
  • That didnt really help. However, disabling runtime themes did. Thanks. – Alexander Rykunov Jan 22 '16 at 16:19
  • 1
    You did it wrong. Setting `ParentBackground` to `False` does indeed allow the panel's specified color to show up. Disabling runtime themes is surely not the correct solution. That said, your current approach is not the correct solution to drawing a chess board. – David Heffernan Jan 22 '16 at 16:20

0 Answers0