Solved

VB.net 2010 - Stop a animated GIF?

Posted on 2011-02-27
8
2,548 Views
Last Modified: 2012-05-11
Hello,

I have an an image I've simply loaded with:

PImage(i).Image = Image.FromFile(ItemsFolder & "test.gif")

This will load the test.gif image in my picturebox, the thing is, I don't want it to play until I hover over it. I know how to use the mouseover function, but I'm not sure how to stop an animated gif from playing when it is loaded.

Is there any simple way of doing this?

Thank you.
0
Comment
Question by:Valleriani
[X]
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
  • 5
  • 3
8 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 34991233
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 34991247
0
 
LVL 7

Author Comment

by:Valleriani
ID: 34991319
ImageAnimator seems to work great if painting to the form, however, I have a define like this:

Public PImage() As System.Windows.Forms.PictureBox ... Then I redim it depending on the amount of images specified for the layout. By default, it is 15 images, so 0 to 14.

I can't seem to get the PAINT handler working when I defined the PImage, If I try something like:

Public Sub PImage_Paint(ByVal sender As Object, ByVal e As System.EventArgs) Handles PImage.Paint
...
End Sub

I end up getting an:
Error      2      Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

I tried to look online, but I don't understand fully how to handle a paint event in this case, otherwise I think I could get it working. Any ideas?


0
Technology Partners: 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 7

Author Comment

by:Valleriani
ID: 34991349
Actually, I'm getting closer:

In LOAD I call this as an example to (0)

        InitializeComponent()
        AddHandler PImage(0).Paint, AddressOf pictureBox1_Paint



    Public Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
        If Not Rect.Contains(PointToClient(Control.MousePosition)) Then
            Bmp.SelectActiveFrame(New Imaging.FrameDimension(Bmp.FrameDimensionsList(0)), 0)
            ImageAnimator.Animate(Bmp, New System.EventHandler(AddressOf OnChangeFrame))
        End If
        ImageAnimator.UpdateFrames()
        e.Graphics.DrawImage(Bmp, Rect)
    End Sub

This in turn makes it rotate when the image is hovered over, however, its positioning the image rotation depending on the form itself rather then the picture box.

I presume it's this line:

        If Not Rect.Contains(PointToClient(Control.MousePosition)) Then

Causing the issue. But I'm not positive how to make start off the contains at the picturebox instead.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 34991377
Rect is the form rectangle, try using the pictureBox rectangle instead.
0
 
LVL 7

Author Comment

by:Valleriani
ID: 34991410
Sorry, I do not follow what you mean by picturebox rectangle?
0
 
LVL 7

Author Comment

by:Valleriani
ID: 34991422
This could be possible too:

        AddHandler PImage(0).Paint, AddressOf pictureBox1_Paint
        AddHandler PImage(0).MouseHover, AddressOf pictureBox1_MH
        AddHandler PImage(0).MouseLeave, AddressOf pictureBox1_ML

    Private Sub OnChangeFrame(ByVal sender As Object, ByVal e As System.EventArgs)
        PImage(0).Invalidate()
    End Sub

    Public Sub pictureBox1_ML(ByVal sender As Object, ByVal e As System.EventArgs)
        Bmp.SelectActiveFrame(New Imaging.FrameDimension(Bmp.FrameDimensionsList(0)), 0)
        ImageAnimator.StopAnimate(Bmp, New System.EventHandler(AddressOf OnChangeFrame))
        PImage(0).Invalidate()
    End Sub

    Public Sub pictureBox1_MH(ByVal sender As Object, ByVal e As System.EventArgs)
        ImageAnimator.Animate(Bmp, New System.EventHandler(AddressOf OnChangeFrame))
    End Sub

    Public Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
        ImageAnimator.UpdateFrames()
        e.Graphics.DrawImage(Bmp, Rect)
    End Sub

The problem is, I can't use Me.Invalidate() because Me = the form. I'm not sure how to make my own overloader function, would be great to specify the index of the control.. Or maybe theres a better way to get the control index.
0
 
LVL 7

Author Closing Comment

by:Valleriani
ID: 34993488
I ended up getting it via using .tag to define the control, so it was easy to find what is what. Thanks!
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Progress
Introduction to Processes

691 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