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