Einzelnen Beitrag anzeigen

Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#3

Re: synchrones scrollen von listview und panels

  Alt 15. Mai 2004, 08:30
Hallo,
ich habe mir mal einen TScrollBox Nachfahren gebastelt, der die Events OnVScroll und OnHScroll hat.
Nebenbei können über die Eigenschaft GroupIndex die Scrollboxen synchronisiert. Evt kannst Du das Prinzip ja auf Dein Problem übertragen.
Delphi-Quellcode:
unit ScrollBoxEx;

interface

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

Const
  CM_SCROLLBOXEXVERTSCROLL = WM_USER+512;
  CM_SCROLLBOXEXHORIZSCROLL = WM_USER+513;

type

  TScrollEvent = procedure (Sender : TObject; Position : Integer) of Object;

  TScrollBoxEx = class(TScrollBox)
  private
    FOnVScroll : TScrollEvent;
    fOnHScroll : TScrollEvent;
    FGroupIndex: Integer;
    procedure SetGroupIndex(const Value: Integer);
    procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;
    procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
    procedure CMSCROLLBOXEXVERTSCROLL(var Message: TMessage); message CM_SCROLLBOXEXVERTSCROLL;
    procedure CMSCROLLBOXEXHORIZSCROLL(var Message: TMessage); message CM_SCROLLBOXEXHORIZSCROLL;
    { Private-Deklarationen }
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    constructor Create(AOwner : TComponent); override;
  published
    { Published-Deklarationen }
    property GroupIndex : Integer read FGroupIndex write SetGroupIndex default 0;
    property OnHScroll : TScrollEvent read fOnHScroll write fOnHScroll;
    property OnVScroll : TScrollEvent read fOnVScroll write fOnVScroll;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Mycomps', [TScrollBoxEx]);
end;

{ TScrollBoxEx }

constructor TScrollBoxEx.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  FGroupIndex:=0;
  fOnVScroll:=Nil;
end;

procedure TScrollBoxEx.SetGroupIndex(const Value: Integer);
begin
  FGroupIndex := Value;
end;

procedure TScrollBoxEx.WMHScroll(var Message: TWMHScroll);
var
  Msg: TMessage;
begin
  inherited;
  If Assigned(fOnHScroll) then
    fOnHScroll(Self,Message.Pos);
  if (FGroupIndex <> 0) and (Parent <> nil) then
  begin
    Msg.Msg := CM_SCROLLBOXEXHORIZSCROLL;
    Msg.WParam := FGroupIndex;
    Msg.LParam := Longint(Self);
    Msg.Result := 0;
    Parent.Broadcast(Msg);
  end;
end;

procedure TScrollBoxEx.WMVScroll(var Message: TWMVScroll);
var
  Msg: TMessage;
begin
  inherited;
  If Assigned(fOnVScroll) then
    fOnVScroll(Self,Message.Pos);
  if (FGroupIndex <> 0) and (Parent <> nil) then
  begin
    Msg.Msg := CM_SCROLLBOXEXVERTSCROLL;
    Msg.WParam := FGroupIndex;
    Msg.LParam := Longint(Self);
    Msg.Result := 0;
    Parent.Broadcast(Msg);
  end;
end;

procedure TScrollBoxEx.CMSCROLLBOXEXVERTSCROLL(var Message: TMessage);
var
  Sender: TScrollBoxEx;
begin
  inherited;
  If FGroupIndex<=0 then Exit;
  if Message.WParam = FGroupIndex then
  begin
    Sender := TScrollBoxEx(Message.LParam);
    if Sender <> Self then
    begin
    VertScrollBar.Position:=Sender.VertScrollBar.Position;
    end;
  end;
end;

procedure TScrollBoxEx.CMSCROLLBOXEXHORIZSCROLL(var Message: TMessage);
var
  Sender: TScrollBoxEx;
begin
  inherited;
  If FGroupIndex<=0 then Exit;
  if Message.WParam = FGroupIndex then
  begin
    Sender := TScrollBoxEx(Message.LParam);
    if Sender <> Self then
    begin
    HorzScrollBar.Position:=Sender.HorzScrollBar.Position;
    end;
  end;
end;

end.
I come from outer space to save the human race
  Mit Zitat antworten Zitat