Listbox diferente

24/09/2004

0

como eu faço para que quando o meu mouse passar por um dos itens de um listbox mudar de cor


Anicetojunior

Anicetojunior

Responder

Posts

24/09/2004

Beppe

Isto vai em public: ItemCorrente: Integer;

ListBox1.Style := lbsOwnerDrawFixed; // ou lbsOwnerDrawVariable

E configure estes eventos:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with TListBox(Control), Canvas do
  begin
    if Index = ItemCorrente then
      Brush.Color := clGreen;
    FillRect(Rect);
    TextOut(Rect.Left, Rect.Top, Items[Index]);
  end;
end;

procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  NovoItem: Integer;
begin
  with TListBox(Sender) do
  begin
    NovoItem := ItemAtPos(ScreenToClient(Mouse.CursorPos), True);
    if NovoItem <> ItemCorrente then
    begin
      ItemCorrente := NovoItem;
      TListBox(Sender).Invalidate;
    end;
  end;
end;



Responder

24/09/2004

Anicetojunior

VALEU D++++++++++++,obrigadaooooooooooooooo,


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar