方法一:
msg: tagmsg;
varhandled: boolean);
begin
//當在 dbgrid1 上發生滑鼠滾輪事件時
if (dbgrid1.focused) and (msg.message = wm_mousewheel) then
begin
if msg.wparam > 0
then //滾輪上滾
sendmessage(dbgrid1.handle, wm_keydown, vk_up,
0) //向dbgrid1傳送 vk_up按鍵訊息
else //下滾
sendmessage(dbgrid1.handle, wm_keydown, vk_down, 0);
handled := true; //訊息已經處理完畢
end;end;
dbgrid1表示需要響應滾輪事件的dbgrid名,這樣就能順利解決滾輪支援的問題。
方法二:
首先在窗體定義前面新寫乙個類,繼承於dbgrids.tdbgrid,新增乙個domousewheel的函式,如下:
type
tdbgrid=class(dbgrids.tdbgrid)
public
function
domousewheel(shift: tshiftstate; wheeldelta: integer;
mousepos: tpoint): boolean; override;
end; tformmain =class(tform)
//....省略
end;var
formmain: tformmain;
implementation
//....其他省略
function
tdbgrid.domousewheel(shift: tshiftstate; wheeldelta: integer;
mousepos: tpoint): boolean;
begin
if wheeldelta < 0
then
datasource.dataset.next;
if wheeldelta > 0
then
datasource.dataset.prior;
end;
end.
DBGrid支援滑鼠滾輪滾動的解決辦法
方法一 msg tagmsg varhandled boolean begin 當在 dbgrid1 上發生滑鼠滾輪事件時 if dbgrid1.focused and msg.message wm mousewheel then begin if msg.wparam 0 then 滾輪上滾 se...
滑鼠滾輪滾動事件wheel
滑鼠的滾輪事件主要有兩種 deltay detail wheeldelta deltamode detail deltax,滑鼠滾輪左右擺動,本屬性是唯讀的。負值,向左 正值,向右。正負方向,跟系統的x座標保持一致。deltay,滑鼠滾輪上下滾動,唯讀。負值,向上 正值,向下。deltamode,屬...
delphi中的DBGRid滑鼠滾動事件
procedure onmousewheel var msg tmsg var handled boolean begin if msg.message wm mousewheel then begin if msg.wparam 0 then begin if dbgrid.focused the...