如何在DBGRID或者STRINGGRID中实现用滚轮进行翻页的功能就象浏
给自己一点时间接受自己,爱自己,趁着下午茶的时间来学习图老师推荐的如何在DBGRID或者STRINGGRID中实现用滚轮进行翻页的功能就象浏,过去的都会过去,迎接崭新的开始,释放更美好的自己。
下面是我实现的(这个用的是键盘的上下按键消息,你也可以改成滚动条消息)。
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;