Recent

Author Topic: [SOLVED] How to make a scrollbox scroll by an increment value?  (Read 6958 times)

knuckles

  • Full Member
  • ***
  • Posts: 122
I have a custom control I will be deriving from TScrollingWinControl.

I am intercepting the WM_HSCROLL and WM_VSCROLL messages and what I would like to do is make the scrollbox snap to a position when scrolling. So for example, instead of smooth scrolling horizontally, instead the scrollbar will jump to the nearest snap/increment. The following worked in Delphi (though cannot test as no longer installed) but I seem unable to get it to work in Lazarus:

Code: Pascal  [Select][+][-]
  1. TMyScrollBox = class(TScrollingWinControl)
  2. private
  3.   procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;
  4.   procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
  5. public
  6.   constructor Create(AOwner: TComponent); override;
  7.   destructor Destroy; override;
  8. end;
  9.  
  10. ........
  11.  
  12. procedure TMyScrollBox.WMHScroll(var Message: TWMHScroll);
  13. begin
  14.   Message.Pos := (Message.Pos div 16) * 16; // increment by 16 for example
  15.   inherited;
  16. end;
  17.  
  18. procedure TMyScrollBox.WMVScroll(var Message: TWMVScroll);
  19. begin  
  20.   Message.Pos := (Message.Pos div 16) * 16; // increment by 16 for example
  21.   inherited;
  22. end;

I know the HorzScrollBar and VertScrollBar has a increment property but that only applies when using the scrollbar arrows, I need the same behavior for actually moving the scrollbars.

I also tried changing HorzScrollBar.Position for example but this bugged even more.

Please advise :)
« Last Edit: May 11, 2016, 08:54:49 pm by knuckles »

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: Intercepting scrollbox messages
« Reply #1 on: May 05, 2016, 01:06:31 am »
Forgot to add, I am using Lazarus v1.6 32bit version on Windows 10 x64.

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: How to make a scrollbox scroll by an increment value?
« Reply #2 on: May 08, 2016, 01:19:54 pm »
Does anyone have any idea how to do this?

Thanks.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to make a scrollbox scroll by an increment value?
« Reply #3 on: May 08, 2016, 09:55:46 pm »
TControlScrollBar calls ScrollBy of the control. You need to override it. To achieve the snap effect don't you need to also change the equation a bit to something like: ((value + 8) div 16) * 16

Michl

  • Full Member
  • ***
  • Posts: 226
Re: How to make a scrollbox scroll by an increment value?
« Reply #4 on: May 08, 2016, 10:17:10 pm »
You can also do something like:
Code: Pascal  [Select][+][-]
  1. procedure TMyScrollBox.WMHScroll(var Message: TWMHScroll);
  2. begin
  3.   case Message.ScrollCode of
  4.     SB_THUMBPOSITION:
  5.       HorzScrollBar.Position := (Message.Pos shr 4) shl 4;
  6.     SB_PAGEDOWN, SB_LINEDOWN:
  7.       HorzScrollBar.Position := (HorzScrollBar.Position) + 16;
  8.     SB_PAGEUP, SB_LINEUP:
  9.       HorzScrollBar.Position := (HorzScrollBar.Position) - 16;
  10.   end;
  11. //  inherited;
  12. end;  
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: How to make a scrollbox scroll by an increment value?
« Reply #5 on: May 11, 2016, 08:54:33 pm »
Thanks, this gives me some ideas to try out some time :)

 

TinyPortal © 2005-2018