您现在的位置:首页 >> VCL >> VCL >> 内容

自定义TWebBrowser浏览器控制滚动条

时间:2011/9/3 16:26:40 点击:

  核心提示:procedure TDxSkinWebBrowser.ReSetWebSize;var WebClientWidth,WebClientHeight: Integer; MaxScrollWidth...
procedure TDxSkinWebBrowser.ReSetWebSize;
var
   WebClientWidth,WebClientHeight: Integer;
   MaxScrollWidth, MaxScrollHeight: Integer;
   webPoint: TPoint;
begin
   if (FWebBrowser.Document <> nil) and ((FWebBrowser.Document  as IHTMLDocument2).body <> nil) then
   begin
     {先获得页面的最大高度}
     if (FScrollBars = ssVertical) or (FScrollBars = ssBoth) then
     begin
       if IsW3CStd then //如果是W3C标准
          MaxScrollHeight := FWebBrowser.oleobject.document.documentelement.ScrollHeight
       else
          MaxScrollHeight := (FWebBrowser.Document  as IHTMLDocument2).body.getAttribute('ScrollHeight', 0);
       if MaxScrollHeight > FWebBrowser.Height  then //总高度大于显示高度度出现滚动条
       begin
          if IsW3CStd then
          begin
            WebClientHeight := FWebBrowser.oleobject.document.documentelement.ClientHeight;
            webPoint.Y := FWebBrowser.oleobject.document.documentelement.scrollTop;
          end
          else
          begin
            WebClientHeight := (FWebBrowser.Document as IHTMLDocument2).body.getAttribute('ClientHeight', 0);
            webPoint.Y := ((FWebBrowser.Document as IHTMLDocument2).body as IHTMLElement2).scrollTop;
          end;
          FVScrollBar.SetRange(0,MaxScrollHeight,webPoint.Y,WebClientHeight);
          FVScrollBar.Visible := true;
       end else FVScrollBar.Visible := False;
     end;
     if (FScrollBars = ssHorizontal) or (FScrollBars = ssBoth)  then
     begin
       if IsW3CStd then //如果是W3C标准
         MaxScrollWidth := FWebBrowser.oleobject.document.documentelement.ScrollWidth
       else
         MaxScrollWidth := (FWebBrowser.Document as IHTMLDocument2).body.getAttribute('ScrollWidth', 0);
       //总宽度大于显示宽度,出现滚动条
       if MaxScrollWidth > FWebBrowser.Width then
       begin
         if IsW3CStd then
         begin
           WebClientWidth := FWebBrowser.oleobject.document.documentelement.ClientWidth;
           webPoint.x := FWebBrowser.oleobject.document.documentelement.ScrollLeft;
         end
         else
         begin
           WebClientWidth := (FWebBrowser.Document as IHTMLDocument2).body.getAttribute('clientWidth', 0);
           webPoint.x := ((FWebBrowser.Document as IHTMLDocument2).body as IHTMLElement2).scrollLeft;
         end;
         FHScrollBar.SetRange(0,MaxScrollWidth,webPoint.X,WebClientWidth);
         FHScrollBar.Visible := True;
       end else FHScrollBar.Visible := False;
     end;
   end;
end;

作者:不得闲 来源:原创
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号