当我拉动其中的一个Listbox的滚动条的时候,另外的一个滚动条跟着动,里面的内容也改变.提示:1. ListBox2.ItemIndex:=ListBox1.ItemIndex;这样只能是选中哪一条的时候同步,如果是拉动滚动条的时候不能实现同步.
2.//监视滚动条移动
  private
    { Private declarations }
      FOldProc : TWndMethod;
    procedure MyProc(var Message:TMessage);procedure TForm1.FormCreate(Sender: TObject);
begin
  FOldProc := ListBox1.WindowProc;
  ListBox1.WindowProc := MyProc;
end;
procedure TForm1.MyProc(var Message: TMessage);
begin
  if message.Msg = WM_VSCROLL then
    begin
      showmessage('触发滚动条');
    end;
  FOldProc(message);
end;

解决方案 »

  1.   

    一个变通的办法,将ListBox2 放入到 ListBox1中,同时显示.如
    010;  北京
    022;  天津
    ...,如果要产生其他事件的话,那就需要自己控制了.
      

  2.   

    两个Listbox里面的内容不同,但是记录条数是一样的,所以做起来就比较麻烦
      

  3.   

    有没有想过不要用Listbox呢?用滚动条来实现下拉
      

  4.   

    那样不好,我想实现同步滚动就是为了比较两个Listbox中的数据,那样看起来就很方便啦
      

  5.   

    procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
    begin
      with msg do
        if hwnd=listbox1.Handle then
           listbox2.Perform(message,wParam,lParam)
        else
          if hwnd=listbox2.Handle then
             listbox1.Perform(message,wParam,lParam);
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnMessage :=appmessage;
    end;
      

  6.   

    // 放置2个TListBox, 1个TApplicationEvents控件(在Additional页)
    // 在ApplicationEvents1控件的OnMessage中写入代码
    // 实现拖动ListBox1的ScrollBar将同步ListBox2的ScrollBar。(内容也同步)procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    var
      WParam: LongWord;
    begin
      if Msg.hwnd = ListBox1.Handle then
      begin
        WParam := GetScrollPos(ListBox1.Handle, SB_VERT);
        WParam := WParam shl 16;
        WParam := WParam + SB_THUMBPOSITION;
        SendMessage(ListBox2.Handle, WM_VSCROLL, WParam, 0);
      end;
    end;