用WebBrowser打开网页后,打算按住鼠标拖动网页内容,实现上下左右移动,请问该如何实现?设置DrapMode为dmAutomatic并无反应。

解决方案 »

  1.   

    我可能还没描述清楚。就是类似pdf那样的功能,打开后用鼠标拖拽页面,实现上下左右平移。
      

  2.   

    var
      r: TRect;procedure TForm1.FormCreate(Sender: TObject);
    begin
      w.navigate('http://www.baidu.com');
      r:=w.BoundsRect;
      dec(r.Right,16);
      dec(r.Bottom,16);
      r.topleft:= clienttoscreen(r.TopLeft);
      r.BottomRight:=clienttoscreen(r.BottomRight);
      application.OnMessage := m;
    end;var
      p: TPoint;procedure TForm1.m(var Msg: TMsg; var Handled: Boolean);
    begin
      if not PtInRect(r, mouse.CursorPos) then Exit;  case Msg.message of
        WM_LBUTTONDOWN:
          begin
            Tag := 1;
            p := Mouse.CursorPos;
            Handled := True;
          end;
        WM_MOUSEMOVE:
          begin
            if Tag = 1 then
            begin
              with Mouse.CursorPos do
                w.OleObject.document.parentWindow.scrollBy(p.X-x,p.Y-y);//网页内容滚动
              p := Mouse.CursorPos;
              Handled := True;
            end
          end;
        WM_LBUTTONUP:
        begin
          Tag := 0;
          Handled := True
        end
     end
    end;