Hide scrollbars in a TWebBrowser
Hide scrollbars in a TWebBrowser
This 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
4 comments. Current rating:
(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:
| ||
| ||
You, sir, are a godsend. | ||
| ||
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' | ||
| ||
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:). |
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