[Solved] Can a thumbnail view be added to the checklistbox? lazarus / 31-LCL ---------------------------------------------------------------------- loaded · 2023-03-30 13:12 Hi All, I need a simple layer manager similar to paint.net's layer manager. Can the following view be made with CheckListBox? If not, should I design a sample layer view inside the panel and duplicate this template at runtime? ---------------------------------------------------------------------- KodeZwerg · 2023-03-30 13:43 I am not that sure about CheckListBox and Bitmaps (as downscaled image) but VirtualStringTree can do it for sure. ---------------------------------------------------------------------- paweld · 2023-03-30 15:21 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 uses  LCLIntf, LCLType; procedure TForm1.FormCreate(Sender: TObject);var  i: Integer;begin  CheckListBox1.ItemHeight := 94;  CheckListBox1.Style := lbOwnerDrawFixed;  for i := 0 to ImageList1.Count - 1 do    CheckListBox1.Items.Add(Format('Image %2d', [i]));end; procedure TForm1.RadioButton1Change(Sender: TObject);begin  CheckListBox1.Invalidate;end; procedure TForm1.CheckListBox1DrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);const  chbState: array [0..1] of Integer = (DFCS_FLAT or DFCS_BUTTONCHECK, DFCS_FLAT or DFCS_BUTTONCHECK or DFCS_CHECKED);var  bmp: TBitmap;  checkboxsize: TSize;  checkboxrect: TRect;  textpoint, imagepoint: TPoint;  th: Integer;begin  with TCheckListBox(Control) do  begin    if Checked[Index] then      Canvas.Font.Style := Canvas.Font.Style + [fsBold];    Canvas.FillRect(ARect);    if Index < Items.Count then  begin      checkboxsize.cx := GetSystemMetrics(SM_CXMENUCHECK);  //checkbox width      checkboxsize.cy := GetSystemMetrics(SM_CYMENUCHECK);  //checkbox height      th := Canvas.TextHeight(Items[Index]);      checkboxrect.Top := ARect.Top + (ARect.Height - checkboxsize.cy) div 2;      checkboxrect.Bottom := checkboxrect.Top + checkboxsize.cy;      textpoint.Y := ARect.Top + ((ARect.Height - th) div 2);      imagepoint.Y := ARect.Top + 2;      if RadioButton1.Checked then      begin        checkboxrect.Left := ARect.Left + 20;        textpoint.X := ARect.Left + 20 + checkboxsize.cx + 20;        imagepoint.X := Arect.Width - ImageList1.Width - 2;      end      else      begin        checkboxrect.Left := ARect.Right - 20 - checkboxsize.cx;         imagepoint.X := ARect.Left + 2;        textpoint.X := imagepoint.X + 160 {img width} + 20;      end;      checkboxrect.Right := checkboxrect.Left + checkboxsize.cx;      DrawFrameControl(Canvas.Handle, checkboxrect, DFC_BUTTON, chbState[Checked[Index].ToInteger]);   //checkbox      Canvas.TextRect(ARect, textpoint.X, textpoint.Y, Items[Index]);   //text      bmp := TBitmap.Create;      bmp.SetSize(ImageList1.Width, ImageList1.Height);      ImageList1.GetBitmap(Index, bmp);      Canvas.Draw(imagepoint.X, imagepoint.Y, bmp);  //image      bmp.Free;    end;  end;end; ---------------------------------------------------------------------- loaded · 2023-03-30 17:26 Special thanks to KodeZwerg and paweld for taking your precious time to reply. In the solution you sent paweld, the checkboxes do not work when they move to the right. Is there a solution for this? If there is no solution, it doesn't matter, I can also use it this way. ---------------------------------------------------------------------- paweld · 2023-03-30 17:43 actually, I didn't check it. the following code solves this problem  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.CheckListBox1DrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);    const    chbState: array [0..1] of Integer = (DFCS_FLAT or DFCS_BUTTONCHECK, DFCS_FLAT or DFCS_BUTTONCHECK or DFCS_CHECKED);var  bmp: TBitmap;  checkboxsize: TSize;  checkboxrect: TRect;  textpoint, imagepoint: TPoint;  th: Integer;begin  with TCheckListBox(Control) do  begin    if Checked[Index] then      Canvas.Font.Style := Canvas.Font.Style + [fsBold];    Canvas.FillRect(ARect);    if Index < Items.Count then  begin      checkboxsize.cx := GetSystemMetrics(SM_CXMENUCHECK);  //checkbox width      checkboxsize.cy := GetSystemMetrics(SM_CYMENUCHECK);  //checkbox height      th := Canvas.TextHeight(Items[Index]);      checkboxrect.Top := ARect.Top + (ARect.Height - checkboxsize.cy) div 2;      checkboxrect.Bottom := checkboxrect.Top + checkboxsize.cy;      textpoint.Y := ARect.Top + ((ARect.Height - th) div 2);      imagepoint.Y := ARect.Top + 2;      if RadioButton1.Checked then      begin        CheckListBox1.BiDiMode := bdLeftToRight; // <-- Add this        checkboxrect.Left := ARect.Left + 20;        textpoint.X := ARect.Left + 20 + checkboxsize.cx + 20;        imagepoint.X := Arect.Width - ImageList1.Width - 2;      end      else      begin        CheckListBox1.BiDiMode := bdRightToLeft;  // <-- and this        checkboxrect.Left := ARect.Right - 20 - checkboxsize.cx;         imagepoint.X := ARect.Left + 2;        textpoint.X := imagepoint.X + 160 {img width} + 20;      end;      checkboxrect.Right := checkboxrect.Left + checkboxsize.cx;      DrawFrameControl(Canvas.Handle, checkboxrect, DFC_BUTTON, chbState[Checked[Index].ToInteger]);   //checkbox      Canvas.TextRect(ARect, textpoint.X, textpoint.Y, Items[Index]);   //text      bmp := TBitmap.Create;      bmp.SetSize(ImageList1.Width, ImageList1.Height);      ImageList1.GetBitmap(Index, bmp);      Canvas.Draw(imagepoint.X, imagepoint.Y, bmp);  //image      bmp.Free;    end;  end;end; ---------------------------------------------------------------------- loaded · 2023-03-30 18:49 Quote from: paweld on March 30, 2023, 07:43:16 pmactually, I didn't check it. the following code solves this problem  Yes it solved. Thank you for every character you write. Respects. ---------------------------------------------------------------------- jamie · 2023-03-31 00:47 Interesting, my old install I like using 2.0.4 laz, the OnMeasureItem isn't published in this control.. Guess it wouldn't really matter in this case. btw, what does the Virtual style do?