unit LView_DrawText_TestU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, ComCtrls;
type
TForm1 =
class(TForm)
ListView1: TListView;
ImageList1: TImageList;
procedure ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
TestStr:
String;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
uses
StrUtils;
{$R *.dfm}
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
//
end;
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
var
Rect: TRect;
a, w: Integer;
begin
DefaultDraw := FALSE;
w := 0;
for a := 0
to SubItem - 1
do
w := w + ListView1.Columns[a].Width;
Rect.Left := (Item.Left - 4 + w) + 2;
Rect.Top := Item.Top + 2;
Rect.Right := Rect.Left + ListView1.Columns[SubItem].Width - 2;
Rect.Bottom := Item.Top + ListView1.SmallImages.Height - 2;
ListView1.Font.Style := [];
// ListView1.Canvas.DrawFocusRect(Rect);
case SubItem
of
1:
begin
ListView1.Canvas.FillRect (Rect);
DrawText (ListView1.Canvas.Handle, PChar (TestStr), Length (TestStr),
Rect, DT_WORDBREAK
or
DT_NOPREFIX
or
DT_WORD_ELLIPSIS);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
li: TListItem;
a: Integer;
begin
TestStr := DupeString('
Der Affe den Sie meinen heißt Parmesan ', 5);
for a := 1
to 10
do
begin
li := ListView1.Items.Add;
// Leak erstmal egal
li.Caption := inttostr (a);
end;
end;
end.