你先在窗体上放一个TApplicationEvents控件(Delphi自带的),找到WmMouseWheelMessage事件。
下面是我实现的(这个用的是键盘的上下按键消息,你也可以改成滚动条消息)。
procedure TMainForm.WmMouseWheelMessage(var Msg: tagMSG;
var Handled: Boolean);
begin
if (DBGrid.Focused) And (Msg.message = WM_MOUSEWHEEL) then
begin
if Msg.wParam > 0 then
SendMessage(DBGrid.Handle, WM_KEYDOWN, VK_UP, 0)
else
SendMessage(DBGrid.Handle, WM_KEYDOWN, VK_DOWN, 0);
Handled := True;
end;
end;
-------------------------------------------------------------------------
问题解决,特别感谢barely(一哥)
DBGRID这么写,先加一个TApplicationEvents,
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if (DBGrid1.Focused) And (Msg.message = WM_MOUSEWHEEL) then
begin
if Msg.wParam > 0 then
SendMessage(DBGrid1.Handle, WM_KEYDOWN, VK_UP, 0)
else
SendMessage(DBGrid1.Handle, WM_KEYDOWN, VK_DOWN, 0);
Handled := True;
end;
end;
stringgrid这么写
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if (stringGrid1.Focused) And (Msg.message = WM_MOUSEWHEEL) then
begin
if Msg.wParam > 0 then
SendMessage(stringGrid1.Handle, WM_KEYDOWN, VK_UP, 0)
else
SendMessage(stringGrid1.Handle, WM_KEYDOWN, VK_DOWN, 0);
Handled := True;
end;
end;