How to hide scroll bar at runtime
Hide
scrollbar - Web Browser Control
Create a new Standard exe
project.
Add Internet Browser control to your Toolbox.
Add
the following controls:
1 Webbrowser control
Name
= WB1
To this time, i think that the only person who knows this trick
is me.
On all forums that i have been visiting is the old same thing:
How could i hide scroll bar from WebBrowser control?.
The answer
always is: Put inside a PictureBox control and set PictureBox's Width
(or, ScaleWidth, i just don't remember ;) to WebBrowser control
minus scroll bar width.
To me, that is a waste of resources. So i
did a little dig and got the following: ' On Declarations section of the form
' that has WebBrowser control.
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Paste
this code in Form_Load event: WB1.navigate "www.angelfire.com"
' And just in case you don't know exact width:
Const SM_CXVSCROLL = 2
Dim ret As Long
ret = GetSystemMetrics(SM_CXVSCROLL)
WB1.Width = WB1.Width - (ret * Screen.TwipsPerPixelX)
And paste this
code in DocumentComplete event of WB1 control: Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB1.Object) Then
WB1.Document.body.setAttribute "scroll", "no"
End If
End Sub
Voilą!. say goodbye to scrollbar.
But, it has an awful
behaviour: If you refresh the page, scroll bar shows again!.
To avoid
this unwanted "error", we have to handle one more event. Private Sub WB1_DownloadComplete()
WB1.Document.body.setAttribute "scroll", "no"
End Sub
There is another way too, see the following code: Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB1.Object) Then
WB1.Document.body.style.overflow ="hidden"
End If
End Sub
You can implement this with an Internet Explorer Object, just
as we have been reading from previous tips. I mean, instead of using wb1
object, declare an object variable (withevents) of type InternetExplorer
and put that code inside appropiate events.
Hope you have enjoyed that work as i did.
;)
©2001 - Richie Simonetti