Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

TElXTree: Mouse Scroll: Only 1 item to be scrolled & Problems with OnMouseScroll

How can the number of lines scrolled be changed from 3 to 1?

I tried the code below, but it increments the TopIndex by 3 as well as by my 1; i.e. making Handled := True doesn't stop the default behaviour. Is this a bug? Please explain.

Also, this event is called twice, so the increment is actually 5. I can work around this by setting a Boolean variable the first time and testing and resetting the 2nd time, but is this expected behaviour or a bug?

Thanks.
Raymond

procedure TMainForm.ItemTreeMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
  with ItemTree do
  begin
    TopIndex := TopIndex - System.Math.Sign(WheelDelta);
  end;

  Handled := True;
end;

Comments

  • 3 Comments sorted by Votes Date Added
  • Posts: 0 Accepted Answer Vote Up0Vote Down
    Hi Raymond,

    TElXTree uses system setting to get number of lines to scroll:

    procedure TElXTreeView.CMMouseWheel(var Msg: TMessage);  { private }
    ...
      if LMDSIWindowsNTUp or LMDSIWindows98 then
        SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, @sl, SPIF_SENDCHANGE)
      else
        sl := 3;
      if sl = 0 then
        sl := 1;

    If you have sources, you can change this. We can add option to select custom number of lines per scroll.

    >>Also, this event is called twice<<
    This is not reproduced on my side. Can you please send me a form with elxtree instance that shows this behavior?

    Best regards,
    Victor Bocharov
    bocharov@lmd.de
  • Top have a property for the number of lines to scroll would be useful.

    However, it would not apply to ListBoxes and other grids and line controls.

    Instead, I have saved the current System value and set it to 1 in Form.OnCreate() and Application.OnActivate, and restore the old value in Application.OnDeactivate().

    var
      SavedWheelScrollIncrement : UINT;

    procedure TMainForm.SaveAndSetWheelScrollLines();
    begin
      if not (    Mouse.MousePresent
              and Mouse.WheelPresent) then
      begin
        Exit;
      end;

      SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, @SavedWheelScrollIncrement, 0);
      SystemParametersInfo(SPI_SETWHEELSCROLLLINES, 1, nil, SPIF_UPDATEINIFILE or SPIF_SENDCHANGE);
    end;

    procedure TMainForm.AppOnDeactivate(Sender: TObject);
    begin
      if not (    Mouse.MousePresent
              and Mouse.WheelPresent) then
      begin
        Exit;
      end;

      SystemParametersInfo(SPI_SETWHEELSCROLLLINES, SavedWheelScrollIncrement, nil, SPIF_UPDATEINIFILE or SPIF_SENDCHANGE);
    end;

    Raymond
Sign In or Register to comment.