Setting the ListBox background color lazarus / 31-LCL ---------------------------------------------------------------------- MaxCuriosus · 2020-02-26 21:21 With the code below I'm trying to set the background color of the sole ListBox in the form, but it does not work as expected. It keeps the default property value. What am I missing? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure TForm1.FormCreate(Sender: TObject);Begin  { Populates the ListBox }  Form1.Color:=clSkyBlue; {works OK}  Form1.ListBox.ParentColor:=False; Form1.ListBox.Color:=clMoneyGreen; {doesn't work, why?}end;                                                                 { Code repopulates ListBox } ---------------------------------------------------------------------- jamie · 2020-02-26 21:27 If you are in windows that is one of the controls bound to the OS themes..  use OwnerDraw style instead where you can then specify your colors and looks at you wish.. ---------------------------------------------------------------------- MaxCuriosus · 2020-02-26 21:50 I am on Debian 9 with Lazarus 2.0.2 / FPC 3.0.4 ---------------------------------------------------------------------- sash · 2020-02-26 22:09 Quote from: MaxCuriosus on February 26, 2020, 10:50:08 pmI am on Debian 9 with Lazarus 2.0.2 / FPC 3.0.4 Which DE and widgetset? For my environment, it works both in IDE's designer and when set in code. ---------------------------------------------------------------------- MaxCuriosus · 2020-02-27 17:45 jamie, on win8/Laz1.8/FPC3.0.4 the same test project works fine without adding anything. It's only on Debian 9 that I have a problem, i.e. I can't control the ListBox background color neither at design time nor at run time. On debian 9 I've tried to add Form1.ListBox.Style:=lbOwnerDrawFixed; or Form1.ListBox.Style:=lbOwnerDrawVariable; but to no avail. sash, my configuration is Lazarus IDE 2.0.2 FPC 3.0.4 x86_64-linux-gtk2 Is this a bug? ---------------------------------------------------------------------- winni · 2020-02-27 19:04 Hi! This seems to mbe a problem with Debian and themes. The workaround goes this way: * Set in the Object Inspector (OI) the Style to lbOwnerDrawFixed * Add to your uses the LCLtype * Connect the event OnDrawItem with the following procedure: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);constCeven = clAqua;Codd = clLime;Cselect = clRed; var col : TColor;beginif odd(index) then col := codd else col := ceven;if odSelected in State then col := Cselect;TListBox(Control).Canvas.Brush.color := Col;TListBox(Control). Canvas.Rectangle(Arect);TListBox(Control).Canvas.Textout (Arect.left+2,Arect.Top+2,TListBox(Control).Items[index] );end; If you become blind by the nice colors you can change the constants. Winni ---------------------------------------------------------------------- sash · 2020-02-27 23:27 @winni: I fear OwnerDrawItem just works as it named: it paints each item (string) after whole box background rectangle was painted. So empty space (in case of number of items is not enough to fill entire box height) will not be covered by your code at all. @MaxCuriosus: Debian 9 is an old release, not to mention Debian are usually (significally) lagging to introduce newer software versions. So even current version (10) doesn't have latest libraries, while ver. 9 doesn't receive any updates (except critical security fixes). So you'd better upgrade. And as I said - it works for Ubuntu (which is basically a not yet released "Debian"). ---------------------------------------------------------------------- winni · 2020-02-27 23:45 Quote from: sash on February 28, 2020, 12:27:21 am@winni: I fear OwnerDrawItem just works as it named: it paints each item (string) after whole box background rectangle was painted. So empty space (in case of number of items is not enough to fill entire box height) will not be covered by your code at all. @sash If too less items is the problem - then there is the old (lousy) trick: Add items with one (or more) #32 until the visible items range is reached. Not a nice solution but helps for  crude desires. Winni ---------------------------------------------------------------------- sash · 2020-02-28 00:09 Quote from: winni on February 28, 2020, 12:45:27 amAdd items with one (or more) #32 until the visible items range is reached. Not a nice solution but helps for  crude desires. As I said, it is working(!) on a recent GTK version. So one simply needs to upgrade 5 years old distro (or maybe switch theme). Not to mention you have to add extra spaces, and then (list controls are made for selecting after all) you have to handle these dummy selected strings. To much interventions in straightforward use of standard control. My advice would be to use ListView instead, or inherit from TCustomListBox and override its Paint for the whole control rectangle. ---------------------------------------------------------------------- winni · 2020-02-28 00:16 @sash Yes - you are right. But he asked for a solution beyond the definition of a ListBox. So I showed how to "enlarge" the definition.That's all! Many different ways lead to Rome ..... Winni ---------------------------------------------------------------------- lucamar · 2020-02-28 11:57 Quote from: sash on February 28, 2020, 01:09:54 amAs I said, it is working(!) on a recent GTK version. So one simply needs to upgrade 5 years old distro (or maybe switch theme). It's working also in older versions, as shows the attached test (code as shown in the first post) made in an Ubuntu 12.04 (so eight years old by now), running a gnome-fallback session (not Unity). Which makes it all the more baffling for the unwary; old Linux hands know that one can't rely on WM/compositors behaving always the same. Re. the image:The form is set to clNavy and the list box to clYellow, in case you didn't notice ---------------------------------------------------------------------- MaxCuriosus · 2020-02-28 22:28 jamie, sash, winni, lucamar, all your points are well taken. And that leaves me ever more perplexed! 1) I have attached the source of this little project whose sole purpose is to test and check stuff and things (button "Choose Year"). Sorry for the non conventional use of lower/upper case in identifiers, I come from FORTRAN and Pascal in the 70s and then Turbo Pascal. Also included are two screenshot cutouts to show the anomaly and the modest objective. 2) The code compiled on Debian 9 will show the anomaly on the same O.S. and also on Tails 4.3 and Debian 10 Live. 3) Could it be that something went wrong during the installation of Lazarus/Pascal or Debian? If so, how could I check it without reinstalling everything? ---------------------------------------------------------------------- winni · 2020-02-28 22:32 Hmmmm - are  some themes at work at the installations??? Winni ---------------------------------------------------------------------- MaxCuriosus · 2020-02-28 22:47 meaning? ---------------------------------------------------------------------- MaxCuriosus · 2020-03-01 22:23 I've tried another way. On another Debian 9 system with the latest updates I've installed Lazarus 2.0.6 and FPC 3.0.4. and compiled the test program. The executable has the same abnormal behavior.