Listview中如何写滚动条的事件,如:当滚动条滚动到底的时候的事件!或拖动滚动条至最上面时的事件。

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Grids, ComCtrls;
    type
      TForm1 = class(TForm)
        ListView1: TListView;
        Button2: TButton;
        Button3: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        FOldProc : TWndMethod;
       procedure MyProc(var message : TMessage);  end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.MyProc(var message: TMessage);
    var
      TheRange,TheRangeMin,TheRangeMax:integer;
      SI: TScrollInfo;begin if message.Msg = WM_VSCROLL then
     begin
        SI.cbSize := SizeOf(TScrollInfo);
        SI.fMask := SIF_ALL;
        GetScrollInfo(listview1.Handle, SB_VERT, SI);
        if SI.nPos + SI.nPage > SI.nMax then ShowMessage('已经到底了!');
        if SI.nPos =SI.nMin then ShowMessage('到头了!');
     end; FOldProc(message);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      FOldProc := listview1.WindowProc;
     listview1.WindowProc := MyProc;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      listview1.Perform(WM_VSCROLL,SB_BOTTOM,0)
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
       listview1.Perform(WM_VSCROLL,SB_TOP,0)
    end;end.