How to implement the function of flipping using the wheel in dbgrid or stringgrid, just like browsing the web?

xiaoxiao2021-03-06  40

You first put a TapplicationEvents control on the form (Delphi comes with it) and finds the WMMouseWheelMelySsage event.

Here is what I implement (this is used by the keyboard up and down button messages, you can also change to the scroll bar message).

Procedure TMAINFORM.WMMMOUSEWHEELMESSAGE (VAR MSG: tagmsg;

Var handled: boolean;

Begin

IF (dbgrid.focused) and (msg.Message = WM_MOUSEWHEEL) THEN

Begin

IF msg.wpaam> 0 THEN

SendMessage (dbgrid.handle, WM_KeyDown, VK_UP, 0)

Else

SendMessage (dbgrid.handle, WM_KeyDown, VK_DOWN, 0);

Handled: = True;

END;

END;

-------------------------------------------------- -----------------------

Problem solving, especially thank Barely (one brother)

DBGRID is written, first plus a TapplicationEvents,

Procedure TFORM1.ApplicationEvents1Message (Var Msg: tagmsg;

Var handled: boolean;

Begin

IF (dbgrid1.focused) and (msg.Message = WM_MOUSEWHEEL) THEN

Begin

IF msg.wpaam> 0 THEN

SendMessage (dbgrid1.handle, WM_KeyDown, VK_UP, 0)

Else

SendMessage (dbgrid1.handle, WM_KeyDown, VK_DOWN, 0);

Handled: = True;

END;

END;

StringGrid is written

Procedure TFORM1.ApplicationEvents1Message (Var Msg: tagmsg;

Var handled: boolean;

Begin

IF (stringgrid1.focused) and (msg.Message = WM_MOUSEWHEEL) THEN

Begin

IF msg.wpaam> 0 THEN

SendMessage (StringGrid1.Handle, WM_KeyDown, VK_UP, 0)

Else

SendMessage (StringGrid1.Handle, WM_KeyDown, VK_DOWN, 0);

Handled: = True;

END;

END;

转载请注明原文地址:https://www.9cbs.com/read-69594.html

New Post(0)