How to use DoMouseWheel to scroll a line at a time?

I wrote a grid control and would like to add mouse wheel support to it. I thought it would be as simple as overriding the DoMouseWheel virtual method, but there is a bit of a problem with it.

You can set the number of lines to scroll at a time in the control panel, and by default, three. And that makes sense when scrolling through a document or web page, but on a grid, I think waiting is more like scrolling a line at a time. But it seems that Delphi wheel support will call DoMouseWheel three times for every label that I scroll, which means that I can only scroll every third row in the grid (or whatever this is a global setting).

How do I scroll one line at a time for each turn of the mouse wheel?

Update: . The short answer here is to simply set Result to True after scrolling - then it does not scroll three times, but only once.

+3
source share
3 answers

Just copy the code from the class TCustomGrid, which overrides both DoMouseWheelDown(), and DoMouseWheelUp()to scroll only one line at a time.

+2
source

In general, it is not a good idea to deal with system settings and / or user preferences. In this case, you must respect what the system or user decided to install while scrolling.

, , , , . , mouseWheel, ( ). , , - , .

+2

JVDBGrid, , DbGrid . : OnMouseWheelDown OnMouseWheelUp.

:.

:

type
  TMyGrid = class(TJvExDBGrid);

procedure TFExample.JvDBGrid1MouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin

  Handled := TMyGrid(Sender).DataLink.DataSet.MoveBy(1) <> 0;

end;

procedure TFExample.JvDBGrid1MouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin

  Handled := TMyGrid(Sender).DataLink.DataSet.MoveBy(-1) <> 0;

end;
0

Source: https://habr.com/ru/post/1721961/


All Articles