Solved

VB.net 2010 - Stop a animated GIF?

Posted on 2011-02-27
8
2,415 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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

813 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

17 Experts available now in Live!

Get 1:1 Help Now