TListView的Item条一般是由系统自画的,但电驴就实现了自画,使之看起来很漂亮,我们用DELPHI也可以实现!
首先要引用CommCtrl单元,这是TListView底层控制单元:
uses
CommCtrl;
//画状态条
procedure DrawSubItem(LV: TListView; Item: TListItem; SubItem: Integer;
Prosition: Single; Max, Style: Integer; IsShowProgress: Boolean;
DrawColor: TColor = $00005B00;
FrameColor: TColor = $00002F00);
//获取SubItem的区域
function GetItemRect(LV_Handle, iItem, iSubItem: Integer): TRect;
var
Rect: TRect;
begin
ListView_GetSubItemRect(LV_Handle, iItem, iSubItem, LVIR_LABEL, @Rect);
Result := Rect;
end;
var
PaintRect, r: TRect;
i, iWidth, x, y: integer;
S: string;
begin
try
with lv do
begin
//LockPaint := True;
PaintRect := GetItemRect(LV.Handle, Item.Index, SubItem);
r := PaintRect;
// if SubItem = DrawSubItem then
Begin
//这一段是算出百分比
if Prosition >= Max then
Prosition := 100
else
if Prosition <= 0 then
Prosition := 0
else
Prosition := Round((Prosition / Max) * 100);
if (Prosition = 0) and (not IsShowProgress) then
begin
//如果是百分比是0,就直接显示空白
Canvas.FillRect(r);
end
else
begin
//先直充背景色
Canvas.FillRect(r);
Canvas.Brush.Color := Color;
// Canvas.FillRect(r);
//画一个外框
InflateRect(r, -2, -2);
Canvas.Brush.Color := FrameColor; //$00002F00;
Canvas.FrameRect(R);
Canvas.Brush.Color := Color;
InflateRect(r, -1, -1);
// Canvas.FillRect(r);
&n