如何在DBGRID或者STRINGGRID中实现用滚轮进行翻页的功能,就象浏览网页一样
2006-02-04 14:00:09 来源:WEB开发网核心提示:你先在窗体上放一个TapplicationEvents控件(Delphi自带的),找到WmMouseWheelMessage事件, 下面是我实现的(这个用的是键盘的上下按键消息,如何在DBGRID或者STRINGGRID中实现用滚轮进行翻页的功能,就象浏览网页一样,你也可以改成滚动条消息), PRocedure
你先在窗体上放一个TapplicationEvents控件(Delphi自带的),找到WmMouseWheelMessage事件。
下面是我实现的(这个用的是键盘的上下按键消息,你也可以改成滚动条消息)。
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;
下面是我实现的(这个用的是键盘的上下按键消息,你也可以改成滚动条消息)。
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;