1
我有一個列表視圖,並希望更改一個項目的字體顏色clred如果用戶雙擊它。但是,如果用戶雙擊其他項目,則所有其他項目都應該返回到黑色字體顏色,並且新的雙擊項目將更改爲clRed - 以此類推。TListview CustomDrawItem更改字體
我有這樣的代碼在這裏:
var
CurrentProfile : String; // Global var that stores the caption of the double clicked item.
procedure TForm1.ListView1DblClick(Sender: TObject);
begin
if ListView1.Selected <> NIL then CurrentProfile := ListView1.Selected.Caption;
end;
procedure TForm1.ListView1CustomDrawItem(
Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
if item.Caption = CurrentProfile then begin
Sender.Canvas.Font.Color := clRed;
end else begin
Sender.Canvas.Font.Color := clBlack; // if not change it back to black
end;
end;
有了這個代碼,每雙單擊項目停留在clRed。爲什麼它不會變回clBlack?請幫忙。先謝謝你。
PS .:我用delphi7。
工程就像一個魅力。謝謝 :) –