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;