Why the child panel do not assume its color?

64 Views Asked by At

Now I am struggling to set the color of a child panel placed on another one.

The goal is to represent fractions of time with certain properties over the whole period, represented by a TPanel on the background(Lime Green).

I do not understand, the code I am using has already worked, but now the child panel keeps the same color of the parent panel.

int IntSize = SecondsBetween( CurrInterrup->TerminoInt, CurrInterrup->InicioInt );
int dura = SecondsBetween( Indisp->DtHoraFim, Indisp->DtHoraIni);
int left = SecondsBetween( Indisp->DtHoraIni, CurrInterrup->InicioInt);
int width = RoundTo(((double)dura /(double) IntSize) *(double) PnGreen->Width, 0);
left  = RoundTo(((double)left/(double)IntSize) * (double)PnGreen->Width, 0);
TPanel *pn = new TPanel(this);
pn->ParentColor = false;
pn->BorderStyle = bsSingle;
pn->BevelKind = bkSoft;
pn->Color  = clRed;
pn->Left   = left;
pn->Width  = width;
pn->Height = PnGreen->Height -5;
pn->Parent = PnGreen; // A Panel instantiated at design time of color clLime 
pn->Update();

The panel "pn" is shown with the correct properties of left, height and width and position, but the color is clLime instead of clRed.

Is there any error on the code?

Thank you very much.

Kind Regards.

1

There are 1 best solutions below

1
Remy Lebeau On

Try setting the panel's ParentBackground property to false.

If ParentBackground is True, the control uses the parent's theme background to draw its own background.

If ParentBackground is False, the control uses its own properties, such as Color, to draw its background.