Delphi开发之:在DBGrid中用Mouse滚动键滚动记录

首先在Unit的 private中写一过程OnMouseWheel。如下:
private
    { Private declarations }
        procedure OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);

 

接着,实现OnMouseWheell过程的代码如下:

Procedure TDeptfrm.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;

以上代码需要更改DBGrid1为你所命名的DBGrid的Name

最后,在FormCreate上来调用以上方法

procedure TDeptfrm.FormCreate(Sender: TObject);
begin
  Application.OnMessage:=OnMouseWheel;
end;

 

完成以上操作,再运运行你的程序,看看结果对不对?

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页