1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
unit UTestLb;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TListBox = class(StdCtrls.TListBox)
private
FOnScroll: TNotifyEvent;
protected
procedure WMVScroll(var Message: TMessage); message WM_VSCROLL;
procedure WMMouseWheel(var Message: TMessage); message WM_MOUSEWHEEL;
public
property OnScroll: TNotifyEvent read FOnScroll write FOnScroll;
end;
////////////////////////////////////
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
procedure FormCreate(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure ListBox2Click(Sender: TObject);
private
{ Déclarations privées }
public
procedure DoScrollListBox1(Sender: TObject);
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure SynchroListBox(ASrc, ADest: TListBox);
var
I: Integer;
begin
if ASrc.MultiSelect and ADest.MultiSelect then
for I := 0 to ASrc.Items.Count - 1 do
If i < ADest.Count Then
ADest.Selected[I] := ASrc.Selected[I];
ADest.TopIndex := ASrc.TopIndex;
ADest.ItemIndex := ASrc.ItemIndex;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.onscroll := DoScrollListBox1;
ListBox2.onscroll := DoScrollListBox1;
end;
procedure TListBox.WMVScroll(var Message: TMessage);
begin
inherited;
if Assigned(FOnScroll) then
FOnScroll(Self);
end;
procedure TListBox.WMMouseWheel(var Message: TMessage);
begin
inherited;
if Assigned(FOnScroll) then
FOnScroll(Self);
end;
//////////////////////////////////
procedure TForm1.DoScrollListBox1(Sender: TObject );
begin
if sender = ListBox1 Then
begin
SynchroListBox(TListBox(Sender),ListBox2)
end
else
if sender = ListBox2 Then
begin
SynchroListBox(TListBox(Sender),ListBox1)
end;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
SynchroListBox(TListBox(Sender),ListBox2)
end;
procedure TForm1.ListBox2Click(Sender: TObject);
begin
SynchroListBox(TListBox(Sender),ListBox1)
end;
end. |
Partager