PDA

View Full Version : Animated Gif Help



Killer Bud
06-09-2010, 10:39 AM
Hello All,

I am using the following set of code to center my animated gif inside my userform which I have pasted below

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)
SePrivate 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)

IMG.Style.backgroundColor = DOC.body.Style.backgroundColor
WebBrowser1.Move -(IMG.offsetLeft * PtX), -(IMG.offsetTop * PtY)

Err_CenterGif:
LockWindowUpdate False
End Sub



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


This code above works flawlessly, when ran from the VBA screen only. Here is my scenario. When the workbook opens, Userform1 starts up. I have a command button on userform1 (commandbutton1) which when clicked then opens up userform2. This is where my problem lies. When userform2 opens the gif is not centered. If I then go into vba and run the code it works perfectly and is centered correctly. Any ideas on how I can fix this? I would attach the file, but you wouldn't be able to see the animated gif anyways.

Just FYI - I removed the following code from the original as I didn't want the frame to center on the userform

Frame1.Move , , IMG.Width * PtX, IMG.Height * PtY
Frame1.Move (Me.InsideWidth - Frame1.Width) / 2, (Me.InsideHeight - Frame1.Height) / 2

Jan Karel Pieterse
06-09-2010, 11:27 PM
Isn't it easier to create a simple html "page" which is set up so the image centers by itself?