procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.style := lbOwnerDrawFixed;
ListBox2.style := lbOwnerDrawFixed;
ListBox2.DoubleBuffered := true;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.canvas do begin
if odSelected in State then
brush.color := clHighlight
else
brush.color := clWindow;
fillrect(rect);
drawtext(handle, pchar(ListBox1.items[index]),
length(ListBox1.items[index]), rect,
DT_VCENTER or DT_SINGLELINE);
end;
ListBox2.topindex := ListBox1.topindex;
ListBox2.refresh;
end;
procedure TForm1.ListBox2DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox2.canvas do begin
if (index < ListBox1.items.count) and
ListBox1.selected[index] then begin
brush.color := clHighlight;
font.color := clWindow;
end else begin
brush.color := clWindow;
font.color := clWindowText;
end;
fillrect(rect);
drawtext(handle, pchar(ListBox2.items[index]),
length(ListBox2.items[index]), rect,
DT_VCENTER or DT_SINGLELINE);
end;
end;