//from Delphi->Help
(*
Here is a typical handler for an OnDrawItem event. In the example, a list box with the lbOwnerDrawFixed styledraws a bitmap to the left of each string.
*)procedure TForm1.ListBox1DrawItem(Sender: TObject; Index: Integer; Rect:TRect; State: TOwnerDrawState);var
Bitmap: TBitmap; { temporary variable for the item抯 bitmap }
Offset: Integer; { text offset width }
begin
with (Sender as TListBox).Canvas do { draw on control canvas, not on the form }
begin
FillRect(Rect); { clear the rectangle }
Offset := 2; { provide default offset }
Bitmap := TBitmap((Sender as TListBox).Items.Objects[Index]); { get the bitmap }
if Bitmap <> nil then begin
Draw(Rect.Left + Offset, Rect.Top, Bitmap); {render bitmap}
Offset := Bitmap.width + 6; { add four pixels between bitmap and text}
end;
TextOut(Rect.Left + Offset, Rect.Top, (Sender as TListBox).Items[Index]) { display the text }
end;
end;
(*
Here is a typical handler for an OnDrawItem event. In the example, a list box with the lbOwnerDrawFixed styledraws a bitmap to the left of each string.
*)procedure TForm1.ListBox1DrawItem(Sender: TObject; Index: Integer; Rect:TRect; State: TOwnerDrawState);var
Bitmap: TBitmap; { temporary variable for the item抯 bitmap }
Offset: Integer; { text offset width }
begin
with (Sender as TListBox).Canvas do { draw on control canvas, not on the form }
begin
FillRect(Rect); { clear the rectangle }
Offset := 2; { provide default offset }
Bitmap := TBitmap((Sender as TListBox).Items.Objects[Index]); { get the bitmap }
if Bitmap <> nil then begin
Draw(Rect.Left + Offset, Rect.Top, Bitmap); {render bitmap}
Offset := Bitmap.width + 6; { add four pixels between bitmap and text}
end;
TextOut(Rect.Left + Offset, Rect.Top, (Sender as TListBox).Items[Index]) { display the text }
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货