private
Procedure OnMouseWheel(Var Msg :TMsg;var Handled:Boolean); 先声明私有过程。
过程如下:
procedure TForm1.OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
begin
if Msg.message = WM_MouseWheel then
begin
if Msg.wParam > 0 then
begin
if DBGrid1.Focused then
SendMessage(DBGrid1.Handle,WM_VSCROLL,SB_PAGEUP,0);
end
else
begin
if DBGrid1.Focused then
SendMessage(DBGrid1.Handle,WM_VSCROLL,SB_PAGEDOWN,0);
end;
Handled:= True;
end;
end;
然后再
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=OnMouseWheel; // 截获鼠标滚动事
ADOQuery1.SQL.Add('select * from 2007各行政区划结果数据2');
ADOQuery1.Open;
end;
即可实现滚轮连动效果。