listbox.items[listbox.itemindex]
当前的item被选中,自然会变色

解决方案 »

  1.   

    用ListBox1DrawItem事件就OK
    procedure TsysForm.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
      ss:string;
    begin
    if odFocused in State then
      begin
         ListBox1.Canvas.Brush.Color:=clBlue;
         ListBox1.Canvas.FillRect(Rect);
         ListBox1.Canvas.Font.color:=clWhite;
      end
      else
      begin
         ListBox1.Canvas.Brush.Color:=clWhite;
         ListBox1.Canvas.FillRect(Rect);
         ListBox1.Canvas.Font.color:=clblack;
      end;
      if Selected[Index] then
         ss:='√'+ListBox1.Items[Index]
      else
         ss:=' '+ListBox1.Items[Index];
      ListBox1.Canvas.textOut(Rect.Left+5,Rect.top+4,ss);
    end;