需求效果如下,原意是多列横向滚动,但是左边标题保持固定,而垂直方向又需要同时向下滚动,不能使用第三方控件,现在的办法是用了两个scrollbox,右边把左边的滚动条盖住了,然后用ApplicationEvents的onmessage事件把两个scrollbox的位置同步,但是问题是响应事件是在滚动结束之后触发的,导致如果按住滚动条按钮不放就会出现一边往下滚另一边还停留不动的现在,只有松手才会位置同步,哪位兄弟有好的解决办法请赐教,另外就是scrollbox的滚动条滚动事件如何捕获,找了一天也没找到,能捕获的话就可以转变思路了啊
万分感谢

解决方案 »

  1.   

    scrollbox1.HorzScrollBar.Position:=xxx; // 控制横向滚动条位置
    scrollbox1.HorzScrollBar.Position:=xxx; // 控制垂直位置也可以用api控制滚动条
    SetScrollInfo
    SetScrollRange
    SetScrollPos捕获滚动条消息就重写wndproc窗口过程,在里面截获WM_VSCROLL、WM_HSCROLL消息
      

  2.   

    procedure WMHScroll(var message: TWMHScroll); message wm_HScroll;
    像这样捕获么,但是对于底层和api几乎没有了解,完全不知道该如何调用
    procedure TFMA2200.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
      if(Msg.message=WM_VSCROLL) or (Msg.message=WM_HSCROLL)then
      begin
        ShowMessage('123');
        if Msg.wParam>0 then
         SendMessage(ScrollBox2.Handle,  WM_VSCROLL,  SB_LINEUP,  0)
        else
         SendMessage(ScrollBox2.Handle,  WM_VSCROLL,  SB_LINEDOWN,  0);
        Handled  :=  True;
      end;
    end;
    在ApplicationEvents的onmessage事件中这样也是捕获不了,求稍微具体点代码提供下思路,万分感谢,已经试了一天了没有进展
      

  3.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        scrlbx1: TScrollBox;
        mmo1: TMemo;
        scrlbx2: TScrollBox;
        mmo2: TMemo;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        FOldWndProc: TWndMethod;
        procedure NewWndProc(var _msg: TMessage);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      FOldWndProc := scrlbx1.WindowProc;
      scrlbx1.WindowProc := NewWndProc;
    end;procedure TForm1.NewWndProc(var _msg: TMessage);
    begin
      FOldWndProc(_msg);  with _msg do
      begin
        case Msg of
          WM_VSCROLL:
            begin
              if WParam <> SB_ENDSCROLL then
                scrlbx2.VertScrollBar.Position := WParamHi;
            end;      WM_HSCROLL:
            begin
              if WParam <> SB_ENDSCROLL then
                scrlbx2.HorzScrollBar.Position := Integer(_msg.WParamHi);
            end;
        end;
      end;
    end;end.
      

  4.   

    // 改下procedure TForm1.NewWndProc(var _msg: TMessage);
    begin
      FOldWndProc(_msg);  with _msg do
      begin
        case Msg of
          WM_VSCROLL:
            begin
              if WParam <> SB_ENDSCROLL then
              begin
                scrlbx1.VertScrollBar.Position := WParamHi; // 加上
                scrlbx2.VertScrollBar.Position := WParamHi;
              end;
            end;      WM_HSCROLL:
            begin
              if WParam <> SB_ENDSCROLL then
              begin
                scrlbx1.HorzScrollBar.Position := WParamHi; // 加上
                scrlbx2.HorzScrollBar.Position := WParamHi;
              end;
            end;
        end;
      end;
    end;
      

  5.   

    十分感谢!昨天忙了点别的事没弄这个,现在滚动条可以完美联动了!
    但是WParamHi这个值为什么一直是空,导致滚动条位置一直是0,给改成scrlbx1.VertScrollBar.Position就好用了,另外如果scrlbx1的滚动条隐藏了,是不是就接收不到消息了?现在只能用控件将其中一个scrlbx的滚动条给隐藏起来达到效果