[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.net 2010 - Stop a animated GIF?

Posted on 2011-02-27
8
Medium Priority
?
2,710 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:Meir Rivkin
ID: 34991233
0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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:Meir Rivkin
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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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…
Six Sigma Control Plans

825 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