你先在窗體上放一個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;