TScrollBox question

Quote
glet...@aol.com (GLetour) wrote:
>I have a drawing pane which is a TScrollBox object. I draw
>on the canvas of this pane with no problem. However, when
>I scroll the pane it doesn't invalidate and redraw the contents.
>That is ok as I want to invoke the drawing myself. Unfortunately,
>I do not see any way to notify myself that a scrollbar OF THE
>SCROLLBOX has been hit. If I had just a scrollbar I would simply
>use the OnScroll event, but the scrollbox does not have a
>corresponding method. How do I see if a scrollbar OF THE
>SCROLLBOX has been hit? By the way, this a Delphi 1.0 program
>compiled under Delphi 1.0.
>Gary Letourneau
>Palet Software, Inc.
>pa...@imssys.com

Try creating a component that is based on the TScrollbox type but
includes an OnScroll event.  You will need to provide a property for
the event procedure and respond to the WM_VSCROLL and WM_HSCROLL
messages. The component could look something like:

TNotifyScrollBox = class(TScrollBox)
private
  fOnScroll: TScrollEvent;
 procedure  WMVScroll(var msg: TWMVScroll); message WM_VSCROLL;
 procedure  WMHScroll(var msg: TWMHScroll); message WM_HSCROLL;
published
  OnScroll: TScrollEvent read fOnScroll write fOnScroll;
end;

implementation

procedure TNotifyScrollBox. WMVScroll(var msg: TWMVScroll);
var
  code: TScrollCode;
begin
  if Assigned(fOnScroll) then begin
   code:= TScrollCode(msg.ScrollCode);
   fOnScroll(self, code, msg.nPos);
  end;
  inherited;
end;

procedure TNotifyScrollBox. WMHScroll(var msg: TWMHScroll);
var
  code: TScrollCode;
begin
  if Assigned(fOnScroll) then begin
   code:= TScrollCode(msg.ScrollCode);
   fOnScroll(self, code, msg.nPos);
  end;
  inherited;
end;

Good Luck,
Steve