Solved

VB.net 2010 - Stop a animated GIF?

Posted on 2011-02-27
8
2,349 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now