?
Solved

Synchronising two scroll boxes

Posted on 2003-02-20
4
Medium Priority
?
196 Views
Last Modified: 2010-04-04
I want to scroll in one scroll box and have another scroll box mirror the scrolling
0
Comment
Question by:NCAnnie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
j42 earned 200 total points
ID: 7986731
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
 
LVL 2

Expert Comment

by:j42
ID: 7986837
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
 
LVL 2

Expert Comment

by:j42
ID: 7986947
Oops, second version is very buggy. You would be better using the first one!

Regards
J
0
 

Author Comment

by:NCAnnie
ID: 7993754
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question