Function GetSubItemRect( handle, ItemsIndex, SubIndex: Integer ): TRect ;
BeginListView_GetSubItemRect( Handle, ItemsIndex, SubIndex, 0, @Result ) ;
End ;
Procedure TFormMain.lvw_listCustomDrawSubItem( Sender: TCustomListView ;
Item: TListItem ;SubItem: Integer ;State: TCustomDrawState ;
Var DefaultDraw: Boolean ) ;
Varl_Rect: TRect ;
l_intPercent: Integer ;
BeginIf SubItem = 3
ThenBeginIf Item.Da
ta = Nil Then
Exit ;
l_intPercent := PListData( Item.Data ).Percent ;
//獲取ListView子項的Rect
l_Rect := GetSubItemRect( Item.Handle, Item.Index, SubItem ) ;
//畫一條外邊框
InflateRect( l_Rect, -1, -1 ) ;
Sender.Canvas.Brush.Color := clBlack ;
Sender.Canvas.FrameRect( l_Rect ) ;
//先填充底色
InflateRect( l_Rect, -1, -1 ) ;
Sender.Canvas.Brush.Color := lvw_list.Color ;
Sender.Canvas.FillRect( l_Rect ) ;
//再根據(jù)進度畫出完成區(qū)域
If l_intPercent = 100 Then
Sender.Canvas.Brush.Color := clGreen
Else
Sender.Canvas.Brush.Color := clPurple ;
l_Rect.Right := l_Rect.Left + Floor( ( l_Rect.Right - l_Rect.Left ) * l_intPercent / 100 ) ;
Sender.Canvas.FillRect( l_Rect ) ;
//恢復(fù)筆刷
Sender.Canvas.Brush.Color := lvw_list.Color ;
//關(guān)鍵的一句,屏蔽系統(tǒng)自繪過程
DefaultDraw := False ;
End ;
End ;
相關(guān)定義
Type
TListData = Record
FileName: String ;
Percent: Integer ;
End ;
PListData = ^TListData ;
本文來自CSDN博客,轉(zhuǎn)載請標(biāo)明出處:http: //blog.csdn.net/kwbin/archive/2008/11/26/3381317.aspx
效果圖: