i've been trying to solve an interesting 'problem', and would like a little guidance: i have a modal
TForm in a project, with a
TPanel sitting in the middle of it (along with an 'OK' button for closing the form). i want the panel to have the
same background colour as the form it is sitting on - at the moment it does
not, they are both slightly different shades of grey. both the form and the panel have the colour set to
clDefault; i don't really want to override these defaults. clearly
clDefault is not a specific colour.
this is all running on Linux, using the GTK2 widget set, but i am hoping for a fairly universal solution.
the form (Form6) is created with the code:
procedure TForm1.Button1Click(Sender: TObject);
var f:TForm6;
begin
f:=TForm6.Create(nil);
try
if f.ShowModal=mrOK then
begin
end
finally
f.Release
end
end;
so far, the most 'sensible' solution i've found to having both form and panel the same colour is this:
procedure TForm6.FormPaint(Sender: TObject);
begin
Panel1.Color:=Self.Canvas.Pixels[Self.Width-5, Self.Height-5]
end;
the above code just picks up the colour of a pixel near the bottom right of the form and sets the panel colour to match.
the
OnPaint event handler seems to be just the wrong place to be doing this - but it is the only place where it works, apart from having that one line of code instead sitting in a
TTimer event. if trying to pick up the colour too early, it is grabbed from a pixel
behind where the form is about to be drawn.
can anyone think of a better and/or 'more proper' solution?
cheers,
rob :-)