web browser on userform

Kris75

Board Regular
Joined
Jul 29, 2009
Messages
143
How do i make my gif, fit dead centre to my web browser control?
without having a large web browser window?

in essence how do i crop my web browser control to fit snugly around my small gif
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Thanks andrew,

Not sure i fully understand
this is my current code

Private Sub UserForm_Initialize()
Me.WebBrowser1.Navigate "\\RC-FILESVR-4\RCHOME$\ky6141\My Documents\My Pictures\kris.gif"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Me.WebBrowser1.Document.Body.Scroll = "no"
End Sub

how can i fit yours into this one?

thanks again
 
Upvote 0
Here is an example of centering a GIF with the same backcolor as the parent container. Download the example which shows various sized animated gifs that are automatically centered when they are loaded. To crop the browser, place it within a frame. When the picture is loaded, the WebBrowser's DocumentComplete event fires and calls code that automatically centers the image by negatively offsetting the browser and resizing the frame. The code also demostrates how to dynamically change style. You have all of the DOM's styles available to you. At least the one that apply to images in this case. Use the color palette and not system colors. If you choose to use system colors, we will need to add a few more API functions to determine what the color actually is. (Of the frame)

<a href="http://cid-ea73b3a00e16f94f.skydrive.live.com/embedicon.aspx/Mr%20Excel%20Example/CenterGifOnUserForm.zip">Center Gif on Userform Example</a>

Code:
Private Sub UserForm_Initialize()
    WebBrowser1.Navigate "http://www.animationplayhouse.com/25.gif"
End Sub

Private Sub CenterGif()
    Dim PtX As Single, PtY As Single, DOC As Object, IMG As Object
    On Error GoTo Err_CenterGif
    LockWindowUpdate FindWindow(vbNullString, Me.Caption)
    Set DOC = WebBrowser1.Document
    PtX = 72 / DOC.parentWindow.screen.logicalXDPI
    PtY = 72 / DOC.parentWindow.screen.logicalYDPI
    Set IMG = DOC.images(0)
    DOC.body.Style.backgroundColor = VBColorToHTML(WebBrowser1.Parent.BackColor)
    IMG.Style.backgroundColor = DOC.body.Style.backgroundColor
    WebBrowser1.Move -(IMG.offsetLeft * PtX), -(IMG.offsetTop * PtY)
    Frame1.Move , , IMG.Width * PtX, IMG.Height * PtY
    Frame1.Move (Me.InsideWidth - Frame1.Width) / 2, (Me.InsideHeight - Frame1.Height) / 2
Err_CenterGif:
    LockWindowUpdate False
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    CenterGif
End Sub

Private Function VBColorToHTML(ByVal Color As Long) As String
    Dim tmp As String
    tmp = Right$("00000" & Hex$(Color), 6)
    VBColorToHTML = "#" & Right$(tmp, 2) & Mid$(tmp, 3, 2) & Left$(tmp, 2)
End Function
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,996
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top