1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, XPMan;
type
TListViewState = (lvsNormal, lvsFocused, lvsDisabled);
TListItemState = (lisNormal, lisSelected);
TListViewColorSet = record
TextColor : TColor;
BackgroundColor : TColor;
end;
const
Orange =$000080FF;
DefaultTextColor = clblack;
DefaultBackgroundColor = clWhite;
ListViewColors : array[TListViewState, TListItemState] of TListViewColorSet =
(
// lvsNormal
(
(TextColor : clBlack; BackgroundColor : clDefault), // livNormal
(TextColor : Orange; BackgroundColor : clBlack) // livSelected
),
// lvsFocused
(
(TextColor : clBlack; BackgroundColor : clDefault), // livNormal
(TextColor : Orange; BackgroundColor : clBlack) // livSelected
),
// lvsDisabled
(
(TextColor : clSilver; BackgroundColor : clDefault), // livNormal
(TextColor : clWhite; BackgroundColor : clBtnFace) // livSelected
)
);
type
TForm1 = class(TForm)
ListView1: TListView;
Edit1: TEdit;
procedure ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
listView1.Enabled := not listView1.Enabled ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
listView1.DoubleBuffered := true;
end;
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
if not Sender.RowSelect then
begin
if Sender.Enabled then
begin
Sender.Canvas.Brush.Color := DefaultBackgroundColor;
Sender.Canvas.Font.Color := DefaultTextColor;
end
else
begin
Sender.Canvas.Brush.Color := clWhite;
Sender.Canvas.Font.Color := clSilver;
end;
end;
end;
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
ListState : TListViewState;
ItemState : TListItemState;
begin
// Force les couleurs par défaut
Sender.Canvas.Brush.Color := DefaultBackgroundColor;
Sender.Canvas.Font.Color := DefaultTextColor;
if not Sender.Enabled then
begin
ListState := lvsDisabled;
end
else
begin
if Sender.Focused then
begin
ListState := lvsFocused;
end
else
begin
ListState := lvsNormal;
end;
end;
if Item.Selected then
begin
ItemState := lisSelected;
end
else
begin
ItemState := lisNormal;
end;
if ListViewColors[ListState][ItemState].BackgroundColor <> clDefault then
Sender.Canvas.Brush.Color := ListViewColors[ListState][ItemState].BackgroundColor;
if ListViewColors[ListState][ItemState].TextColor <> clDefault then
Sender.Canvas.Font.Color := ListViewColors[ListState][ItemState].TextColor;
end;
end. |
Partager