delphi DBgrid 資料隨著滑鼠滾動而滾動!
阿新 • • 發佈:2018-12-07
首先要在窗體放一個ApplicationEvents控制元件,在onApplicationEvents 事件中加入以下程式碼(第一法:只對指定名的控制起作用,第二個對類起作用)
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; ———————————————————————————————————————————————————————— 方法二: //給DBGrid加上滑鼠滾輪 var hWnd: THandle; aName: array [0..255] of char; begin 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;
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; ———————————————————————————————————————————————————————— 方法二: //給DBGrid加上滑鼠滾輪 var hWnd: THandle; aName: array [0..255] of char; begin 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;