Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How do I control WebBrowser attributes (bg color; scroll bars; etc)

Posted on 2001-08-03
Medium Priority
Last Modified: 2012-06-27
I am using WebBowser component in shdocvw.dll to display animated gif inside a form.  I would like to simply display the gif, without any scroll bars, borders and have the background color match the form.
If there is another way to display the gif, I'm open for suggestions.

WebBrowser1.Navigate "file.gif"


Question by:RUSS_EMI
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
LVL 28

Expert Comment

ID: 6350866
>>without any scroll bars

the most common workaround is to place the webbrowser control inside of another container, and position it such that the scroll bars are hidden, such as a frame or picturebox control.

>>and have the background color match the form

this would require that you edit the gif to have the background color you desire.

Expert Comment

ID: 6350951
>>and have the background color match the form

I thought he meant the background color of the webbrowser control? Just in case, here's how to do that easily:

WB.Navigate "about:blank" 'Clear the last document first!
WB.Document.Write "<body bgcolor=#C0C0C0><img src=" & Chr$(34) & "file.gif" & Chr$(34) & ">"

Expert Comment

ID: 6350954
As Azra (do you mind "Azra"?) said, you will need to put the WB control inside another container (such as a picbox) and resize it just right to hide the scrollbars and border.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 14

Expert Comment

ID: 6351372
LVL 14

Expert Comment

ID: 6351381
From Vb2TheMax:
The standard PictureBox control doesn't support the Animated GIF graphic format. However, you can display these images by using a WebBrowser control:

WebBrowser1.Navigate "c:\Images\Animated.Gif"

The only problem of this technique is that the WebBrowser control also displays a vertical and/or horizontal scroll bar. You can hide these scrollbars, if you wish, simply by putting the WebBrowser control inside a PictureBox control, whose width and height is smaller than the WebBrowser control. The following code snippet does that programmatically via the Add method of the Controls collection (requires VB6):

Private Declare Function GetSystemMetrics Lib "user32" Alias "GetSystemMetrics" _
    (ByVal nIndex As Long) As Long
Private Const SM_CXVSCROLL = 2
Private Const SM_CYHSCROLL = 3

' create a new PictureBox
Dim picBox As PictureBox
Set picBox = Controls.Add("VB.PictureBox", "picBox")

' resize the picture box so that it can hide the
' WebBrowser's scroll bars    
With WebBrowser1
    picBox.Move .Left, .Top, .Width - ScaleX(GetSystemMetrics(SM_CXVSCROLL), _
        vbPixels), .Height - ScaleY(GetSystemMetrics(SM_CYHSCROLL), vbPixels)
    ' move the WebBrowser inside the picture box
    Set WebBrowser1.Container = picBox
    ' ensure that the WebBrowser's border isn't visible
    .Move -ScaleX(2, vbPixels), -ScaleY(2, vbPixels)
End With

' all controls are created invisible
picBox.Visible = True


Author Comment

ID: 6351399
As I have variable size animated gifs to display wsh2's answer is most correct, but it doesn't address the background color issue.
I tried using .document.write "<...>" and got a run time error 91.  "Object or With variable block not set".
Please advice.

Thank you,


Author Comment

ID: 6351452
Ammending my last comment;
I can't seem to center the gif and minimize the area around it. This is in addition to the color question.
LVL 28

Accepted Solution

AzraSound earned 150 total points
ID: 6351558

WebBrowser.Navigate "about:blank"
Do While WebBrowser.ReadyState <> READYSTATE_COMPLETE
WebBrowser.Document.write strHTML

>>do you mind "Azra"?

either that or "sexy", whichever you prefer...

Author Comment

ID: 6351566
Azra or "Sexy" (as you prefer);
   The more complicated solution of wsh2 didn't work, because of the inability to center and color correctly.
Thank you for your quick response.


Expert Comment

ID: 6352356
I'm afraid I'd need to know a little more about you before I'd use "sexy"! <grin>

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question