如何让DbGrid支持鼠标滚轮滚动 在主窗体上加一个ApplicationEvents控件(控件在Additional面板中), 在它的OnMessage事件中加入下述代码,一切搞定~! procedure TFrm_main_usermanager.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); var hWnd: THandle; aName: array [0..255] of char; begin //给DBGrid加上鼠标滚轮 if Msg.message <> WM_MOUSEWHEEL then exit; hWnd := WindowFromPoint(msg.pt); if boolean(GetClassName(hWnd, aName, 256))and(aName=‘TDBGrid‘) then//如果第三方控件需要修改,比如用aName=‘TbsSkinDBGrid‘ begin if Short(HIWORD(Msg.wParam)) < 0 then begin PostMessage(hWnd, WM_KEYDOWN, VK_DOWN, 0); PostMessage(hWnd, WM_KEYUP, VK_DOWN, 0) end else begin PostMessage(hWnd, WM_KEYDOWN, VK_UP, 0); PostMessage(hWnd, WM_KEYUP, VK_UP, 0); end; Handled := true; end; end;
并非原创,出自网络
时间: 2024-12-18 00:00:03