ListView Report 方式下自画, 拉动上面的 Header 之后,上一次画上去的不消失呢?(100分)

  • 主题发起人 主题发起人 QSmile
  • 开始时间 开始时间
Q

QSmile

Unregistered / Unconfirmed
GUEST, unregistred user!
我把 TListView 的 设为自画.
再在 OnDrawItem 中写入

var
bkcolor,ftcolor:TColor;
i:Integer;
x:integer;
begin
if odSelected in state then
begin
bkcolor:=$00C56549;
ftcolor:=clWhite;
end
else begin
ftcolor:=clBlack;
if Item.Index mod 2 = 0 then
bkcolor:=$00F2FAFD
else
bkcolor := clWhite;
end;
with TListView(Sender) do
begin
Canvas.Brush.Color:=bkColor;
Canvas.Font.Color:=ftcolor;
Canvas.FillRect(Rect);
if SmallImages<>nil then
begin
SmallImages.Draw(Canvas,Rect.Left+1,Rect.Top+1,Item.ImageIndex);
Canvas.TextOut(Rect.left+1+SmallImages.width,Rect.Top+1,Item.caption);
end
else
Canvas.TextOut(Rect.left+1,Rect.Top+1,Item.caption);

x := 1;
for i:= 0 to Item.SubItems.Count -1 do
begin
x:= x + TListView(Sender).Columns.Width ;
Canvas.TextOut(x+2,Rect.Top +1, Item.SubItems);
end;

end;

这样显示都正常,但如果拉动了上面的 Column 后,下面上一次自画的内容不会消失呢?
如何处理?

比如我拉第三列,向后拉.这时以前第三列显示的内容还在那里.要如何修?.
 
谁做过?11111111111??
 
刷新试试
 
问题是 ListView 没有拉动 Column 的事件呀
 
没看懂你的意思,郁闷中。。。呵呵
 
http://bbs.2ccc.com/topic.asp?topicid=237086

这里有图,你看了就明白了.
 
转别人的方法,你自己再精简一下就可以了,转移代码时注意uses中的单元引用

{***************************************************************
*
* Project Name: LVTest -- Main
* Typist: XJG(xianjun@163.net)
* Purpose:
* Comment Time: 2002-12-2 16:03:20
* History: Create by xjg.
*
****************************************************************}

unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;

type
TForm1 = class(TForm)
ListView1: TListView;
Memo1: TMemo;
private
{ Private declarations }
FHeaderHandle: THandle;
FHeaderInstance: Pointer;
FDefHeaderProc: Pointer;
FMouseDowned: Boolean;
FWidths: array of Integer;
procedure HeaderWndProc(var Message: TMessage);
public
{ Public declarations }
procedure Loaded; override;
destructor Destroy; override;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses CommCtrl;

destructor TForm1.Destroy;
begin
if FHeaderHandle <> 0 then
SetWindowLong(FHeaderHandle, GWL_WNDPROC, Longint(FDefHeaderProc));
FreeObjectInstance(FHeaderInstance);
inherited;
end;

procedure TForm1.HeaderWndProc(var Message: TMessage);

procedure RecordCurWidths;
var
I: Integer;
begin
SetLength(FWidths, ListView1.Columns.Count);
for I := 0 to High(FWidths) do
FWidths := ListView1.Columns.Width;
end;

procedure CompareWidths;
var
I: Integer;
begin
for I := 0 to High(FWidths) do
if FWidths <> ListView1.Columns.Width then
begin
//在这里添加你刷新Listview方法!!!
Memo1.Lines.Add(Format('Column %d: %d --> %d', [I, FWidths,
ListView1.Columns.Width]));
end;
end;
begin
with Message do
begin
Result := CallWindowProc(FDefHeaderProc, FHeaderHandle, Msg, WPARAM, LPARAM);
if Msg = WM_LBUTTONDOWN then
begin
FMouseDowned := True;
RecordCurWidths;
end
else if Msg = WM_LBUTTONUP then
begin
if FMouseDowned then
begin
CompareWidths;
FMouseDowned := False;
end;
end
else if Msg = WM_LBUTTONDBLCLK then
CompareWidths;
end;
end;

procedure TForm1.Loaded;
begin
inherited;
FHeaderHandle := ListView_GetHeader(ListView1.Handle);
FHeaderInstance := MakeObjectInstance(HeaderWndProc);
FDefHeaderProc := Pointer(GetWindowLong(FHeaderHandle, GWL_WNDPROC));
SetWindowLong(FHeaderHandle, GWL_WNDPROC, Longint(FHeaderInstance));
end;

end.
 
多谢楼上的,由于你的提示,我找到了更简单的方法了.
用 ListView_GetColumnWidth
 
多人接受答案了。
 
后退
顶部