procedure TForm1.PaintBoxPaint(Sender: TObject);
var
pb: TPaintBox;
txt: String;
begin
pb := Sender as TPaintBox;
pb.Canvas.Brush.Color := clMoneyGreen;
pb.Canvas.FillRect(ClientRect);
pb.Canvas.Font.name := 'Tahoma';
pb.Canvas.Font.Color := clBlue;
if pb = Paintbox1 then
txt := Listbox.Items[0]
else if pb = Paintbox2 then
txt := Listbox.Items[1]
else if pb = Paintbox3 then
txt := Listbox.Items[2]
else
exit
TextOut(0, 0, txt);
end;
procedure TForm1.ListBoxSelectionChange(Sender: TObject; User: Boolean);
begin
(Sender as TListbox).Invalidate;
end;