Recent

Author Topic: [solved] lbOwnerDrawFixed - minor niggles  (Read 1488 times)

andyH

  • Jr. Member
  • **
  • Posts: 99
[solved] lbOwnerDrawFixed - minor niggles
« on: March 28, 2021, 10:35:52 pm »
I found this:
https://forum.lazarus.freepascal.org/index.php?topic=42397.0 
Which led me to define this:
Code: Pascal  [Select][+][-]
  1. procedure TBasePanel.BoldOS(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);
  2. begin
  3.   with (Control as TCheckListBox).Canvas do
  4.        begin
  5.          if MyDrives.isOS((Control as TCheckListBox).Items[Index]) then Font.Style:= [fsBold];
  6.          TextOut(ARect.Left, ARect.Top,(Control as TCheckListBox).Items[Index]);
  7.        end;
  8. end;
With the relevant TCheckListBox:
Code: Pascal  [Select][+][-]
  1. Box2.Style:= lbOwnerDrawFixed;
  2. Box2.OnDrawItem:= @BoldOS;

MyDrives.isOS checks to see if a partition has an operating system on it and if true, sets the font bold for the relevant TCheckListBox item.

The niggles are that relative to an unmodified TCheckListBox (boxd screenshot), the text in the modified TCheckListBox (boxp screenshot) is placed closer to the checkbox and the text is aligned top instead of centre.

Posted in the linux subforum just in case it is GTK dependent.

Is there any way to get the alignment and spacing with lbOwnerDrawFixed the same as an unmodified TCheckListBox?
« Last Edit: March 28, 2021, 10:55:42 pm by andyH »

andyH

  • Jr. Member
  • **
  • Posts: 99
Re: lbOwnerDrawFixed - minor niggles
« Reply #1 on: March 28, 2021, 10:55:24 pm »
Should have googled textout before I posted  :(

Fixed:
Code: Pascal  [Select][+][-]
  1. procedure TBasePanel.BoldOS(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);
  2. begin
  3.   with (Control as TCheckListBox).Canvas do
  4.        begin
  5.          if MyDrives.isOS((Control as TCheckListBox).Items[Index]) then Font.Style:= [fsBold];
  6.          TextOut(ARect.Left+5, ARect.Top+3,(Control as TCheckListBox).Items[Index]);
  7.        end;
  8. end;

 

TinyPortal © 2005-2018