Witam wszystkich....
Nie wiem jak napisać procedurę obsługującą OwnerDrawFixed, tak aby selekcja Itemów była w innym kolorze niż niebieski.
Przykład programu jest poniżej. Gdy klikam na jakimś Itemie, to zaznacza prawidłowo na czerwono. Problem w tym, że jak kliknę na inny Item, to poprzedni (czerwony) zostaje.
Jak zrobić, żeby tło pod wybranym Itemem było czerwone, a tła pozostałych Itemów - były odświeżane?
Pozdrawiam
RYGAR
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ImgList;
type
TForm1 = class(TForm)
ImageList1: TImageList;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
LINIE : array[0..4] of String[10] =
('Linia 1', 'Linia 2', 'Linia 3', 'Linia 4', 'Linia 5');
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
if Index = ListBox1.ItemIndex then ListBox1.Canvas.Brush.Color := clRed;
ListBox1.Canvas.FillRect(Rect);
ListBox1.Canvas.TextOut(Rect.Left+1,Rect.Top+1,ListBox1.Items.Strings[Index]);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
for I := 0 to 4 do
ListBox1.Items.Add(LINIE[i]);
end;
end.