Einzelnen Beitrag anzeigen

Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.768 Beiträge
 
Delphi 10.4 Sydney
 
#2

Re: 2 Scrollbars gleichsetzen

  Alt 23. Dez 2008, 11:52
Hallo Tim,

hier ist ein Beispiel mit zwei RichEdit zu finden vielleicht kannst Du es an Deine Bedürfnisse anpassen.

Delphi-Quellcode:
//************************* Source for the TMyRichEdit component...

unit Unit1;

interface

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

type
  TMyRichEdit = class(TRichEdit)
    protected
      procedure OnWMHScroll(var Message : TMessage); message WM_HSCROLL;
      procedure OnWMVScroll(var Message : TMessage); message WM_VSCROLL;
      procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
    public
      SyncWithRichEdit : TRichEdit;
  end;

procedure Register;

implementation

uses
  RichEdit;

{ TMyRichEdit }

procedure TMyRichEdit.OnWMHScroll(var Message: TMessage);
begin
  SendMessage(SyncWithRichEdit.Handle, WM_HSCROLL, Message.WParam, Message.LParam);
end;

procedure TMyRichEdit.OnWMVScroll(var Message: TMessage);
begin
 SendMessage(SyncWithRichEdit.Handle, WM_VSCROLL, Message.WParam, Message.LParam);
 inherited;
end;

procedure TMyRichEdit.CNNotify(var Message: TWMNotify);
var
  Diff : Integer;
  c : integer;
begin
  Inherited;
  with Message do
    case NMHdr^.code of
      EN_SELCHANGE:
      begin
        Diff := SyncWithRichEdit.Perform(EM_GETFIRSTVISIBLELINE, 0, 0) -
                 Perform(EM_GETFIRSTVISIBLELINE, 0, 0);
        c := abs(diff);
        while c > 0 do
          begin
            if diff < 0 then
              SyncWithRichEdit.perform(em_scroll, SB_LINEDOWN, 0)
             else
              SyncWithRichEdit.perform(em_scroll, SB_LINEUP, 0);
            dec(c);
          end;
      end;
    end;
end;


procedure Register;

begin
  RegisterComponents('Samples', [TMyRichEdit]);
end;

end.

//************************* Form to test it with - just put a TRichEdit and a TMyRichEdit on it
unit RicheditForm;

interface

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

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    MyRichEdit1: TMyRichEdit;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyRichEdit1.SyncWithRichEdit := RichEdit1;
end;
Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat