Solved

VB.net 2010 - Stop a animated GIF?

Posted on 2011-02-27
8
2,453 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…

840 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