Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does anyone know how to play a GIF animation only once?

Status
Not open for further replies.

piscis

Programmer
Jun 26, 2003
29
PR
Does anyone know how to play a GIF animation only once?

I’m using ImageAnimator class with a GIF animation that was designed with Animation Shop 3 to play or loop only once. When using the code below the animation starts looping repeatedly.

Does anyone know the right code to play this GIF animation one time only?

Thanks

Andy

This is the code I’m using:

'Create a Bitmpap Object.
Private WaterDropAnimation As New Bitmap("WaterDrop.gif")
Private currentlyAnimating As Boolean = False

'This method begins the animation.
Public Sub AnimateImage()
If Not currentlyAnimating Then
'Begin the animation only once.
ImageAnimator.Animate(WaterDropAnimation, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = True
End If
End Sub

Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
'Force a call to the Paint event handler.
Me.Invalidate()
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)


'Get the next frame ready for rendering.
ImageAnimator.UpdateFrames()
'WaterDropAnimation.MakeTransparent(WaterDropAnimation.GetPixel(0, 0))
'Draw the next frame in the animation.
e.Graphics.DrawImage(Me.WaterDropAnimation, New Point(125, 125))

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Begin the animation.
AnimateImage()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If currentlyAnimating Then
'Begin the animation only once.
ImageAnimator.StopAnimate(WaterDropAnimation, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = False
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top