i was recently adding an
InputQuery to a project, and noticed that there was a rectangular box of
slightly different colour to the left of the "OK" and "Cancel" buttons. from a previous problem i realized that these buttons must be sitting within a panel and that the panel was not correctly picking up the colour of its parent. here is a capture of the
InputQuery from my project, see image at end of post.
now bear in mind, i'm running Linux, and using the GTK2 widgetset. chances are this problem will not arise under Windows.
the problem is created in the function
DefaultInputDialog, which is where
InputQuery finally ends up - that took quite a bit of digging to find out!
DefaultInputDialog creates the two buttons at the bottom-right of the form using the following code:
with TButtonPanel.Create(Form) do
begin
Top := Edit.Top + Edit.Height;
Parent := Form;
ShowBevel := False;
ShowButtons := [pbOK, pbCancel];
Align := alTop;
end;
now, what is MISSING is a single line:
with TButtonPanel.Create(Form) do
begin
Top := Edit.Top + Edit.Height;
Parent := Form;
ShowBevel := False;
ShowButtons := [pbOK, pbCancel];
Color:=Parent.GetDefaultColor(dctBrush); // fix for wrong background colour
Align := alTop;
end;
issues around parent colour and the likes is discussed here:
https://forum.lazarus.freepascal.org/index.php/topic,69921.msg544288.htmlmany thanks to
wp for explaining how "The color "clDefault" may be different for each control".
attached below is a sample project demonstrating the issue, and application of the fix. Button1 displays a ButtonPanel using the first set of code from above, while Button2 displays a ButtonPanel using the second set of code (with the extra line). each time you click one of the buttons another ButtonPanel is added; double-clicking on the form anywhere toggles the form's colour setting between
clDefault and pale green, which may help i seeing what is going on.
i believe this fix should be applied to
DefaultInputDialog and anywhere else TButtonPanel is used in creating a set of buttons on a form whose colour has been left as
clDefault. i don't think the fix should be applied
within TButtonPanel, as there are cases where a user may wish to retain the current behavior.
cheers,
rob :-)