Solved

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

Posted on 2001-08-03
10
1,036 Views
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"

Thanks,

Russ
0
Comment
Question by:RUSS_EMI
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 28

Expert Comment

by:AzraSound
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.
0
 
LVL 5

Expert Comment

by:KDivad
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) & ">"
0
 
LVL 5

Expert Comment

by:KDivad
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.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6351372
<ping>
0
 
LVL 14

Expert Comment

by:wsh2
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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:RUSS_EMI
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,

Russ
0
 

Author Comment

by:RUSS_EMI
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.
Russ
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 6351558
try:

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



>>do you mind "Azra"?

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

Author Comment

by:RUSS_EMI
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.

Russ
0
 
LVL 5

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now