delphi

Hide scrollbars in a TWebBrowser

knoen 2014. 1. 26. 13:21

Hide scrollbars in a TWebBrowser

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

How can I hide the scrollbars in my TWebBrowser component?

Answer:

There are two properties in the Document.Body.Style property, named OverflowX and OverflowX. Simply set them to 'hidden' as shown in the code snippet below.

For more information on the TWebBrowser's document properties, see the other tips listed at the top.


begin
  // .. 

  with WebBrowser1.Document.Body.Style do
  begin
    OverflowX := 'hidden';
    OverflowY := 'hidden';
  end; { with WebBrowser1 }
  // ..
end;

 

Scroll a TWebBrowser document to the top/ bottom/ right

 

comments4 comments. Current rating: 5 stars (3 votes). Leave comments and/ or rate it.

Question:

My application uses TWebBrowser and I need to load a document and then have TWebBrowser scroll to the bottom of the document. How can I achieve this? 

Answer:

Create an event on OnDocumentComplete event TForm1.WebBrowser1DocumentComplete() and put this code in there: 

WB_ScrollTo(WebBrowser1, wbPosBottom);

// Scroll to the Bottom, Top, Right of the Document:
type
  TWBPosition = (wbPosBottom, wbPosTop, wbPosRight);
function WB_ScrollTo(WB: TWebBrowser; Position: TWBPosition): Boolean;
var
  ParentW: OLEVariant;
begin
  Result := WB.Document <> nil;
  if Result then
  begin
    ParentW := WB.OleObject.Document.ParentWindow;
    case Position of
      wbPosBottom: ParentW.ScrollTo(0, ParentW.Screen.Height);
      wbPosTop: ParentW.ScrollTo(0, 0);
      wbPosRight: ParentW.ScrollTo(ParentW.Screen.Width, 0);
    end;
  end;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
  WB_ScrollTo(WebBrowser1, wbPosBottom);
end;

Content-type: text/html

Comments:

2006-03-26, 03:55:38
anonymous from Poland   
rating
2006-04-08, 13:39:43
anonymous from United States   
rating
You, sir, are a godsend.
2007-05-27, 04:54:23
anonymous from United Kingdom   
The scroll to bottom doesn't work perfectly - I have a case here when the page is very long, and the WB_ScrollTo(WebBrowser1, wbPosBottom); doesn't scroll all the way down, just down by the height of the screen. i.e. by 'ParentW.Screen.Height'
2009-08-28, 03:18:52
from Hungary   
rating
That's true, Bottom has some problems. 
Not a beauty solution, but if you use a big value (e.g. 10000) instead of ParentW.Screen.Height. It works:).

 

 

Write the next code in onDocumentComplete event:

var
Doc: IHTMLDocument2;
body: OleVariant;
begin
Doc := IHTMLDocument2(WebBrowser.Document);
body := Doc.Body;

{hide scrollbars}
body.Style.BorderStyle := 'none';
body.Scroll := 'no';
end;

With best regards, Mike Shkolnik
http://www.scalabium.com


 

댓글수0