• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Synchronising two scroll boxes

I want to scroll in one scroll box and have another scroll box mirror the scrolling
0
NCAnnie
Asked:
NCAnnie
  • 3
1 Solution
 
j42Commented:
Hi,

I wrote a very simple example. It assumes that the ranges of the scrollbars of the scrollboxes are the same and there is no update of the second scrollbox until you release the mouse button. Maybe it helps you to get on the right track.
Btw, does anybody know what message (WM_...) the 277 is?



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ScrollBox1: TScrollBox;
    ScrollBox2: TScrollBox;
    procedure FormCreate(Sender: TObject);
  private
    FnWinProc: TWndMethod;
    procedure MyWinProc(var Message: TMessage);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  ScrollBox1.VertScrollBar.Range := 1000;
  ScrollBox2.VertScrollBar.Range := 1000;

  FnWinProc := ScrollBox1.WindowProc;
  ScrollBox1.WindowProc := MyWinProc;
end;

procedure TForm1.MyWinProc(var Message: TMessage);
begin
  if (277 = Message.Msg) then
  begin
    ScrollBox2.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position;
  end;

  FnWinProc(Message);
end;

end.
0
 
j42Commented:
This will do better (immediate update of 2nd scrollbox) ;-)



procedure TForm1.MyWinProc(var Message: TMessage);
begin
  FnWinProc(Message);

  if (WM_VSCROLL = Message.Msg) then
  begin
    if (SB_THUMBTRACK = Message.WParamLo) then
    begin
      ScrollBox2.VertScrollBar.Position := Message.WParamHi;
    end;
  end;
end;
0
 
j42Commented:
Oops, second version is very buggy. You would be better using the first one!

Regards
J
0
 
NCAnnieAuthor Commented:
It works very nicely thankyou - I have two boxes and can scroll either and the other scrolls too! even with differing ranges, it was only a scaling problem.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now