File.GIF not running in PictureBox.

Poppa Mintin

Well-known member
Joined
Jan 4, 2018
Messages
45
Programming Experience
10+
Hi,

I'm trying to run a .gif file while playing a tune.
VB.NET:
Imports System.IO

    Private Sub ShowPict(ByVal pic As String)
        PictureBox1.Image = My.Resources.ResourceManager.GetObject(pic)
    End Sub


    Private Sub NoPict()
        PictureBox1.Image = Nothing
    End Sub


    Private Sub PlayTune()
        Dim Sound As MemoryStream
        Sound = DirectCast(My.Resources.ResourceManager.GetObject("Tune"), MemoryStream)
        My.Computer.Audio.Play(Sound, AudioPlayMode.WaitToComplete)
    End Sub
Individually these three subroutines work properly... The file argument 'pic' is a .gif file in rescourses which runs correctly in the PictureBox. I can't find a way to stop the gif file once it's done a cycle so maybe they're not designed to be able to do that. One way to do that would be with a timer accurately set to replace the .gif file with a 'still' (All_Done.png) file.

I figured that a 'WaitToComplete' sound file could be substituted for the timer. So I tried to combine these three sub's thus:
VB.NET:
    Private Sub ShowTime(ByVal pic As String)
        Dim Sound As MemoryStream
        PictureBox1.Image = Nothing ' Clear the pic'box. (Just in case it needs to be empty for the .gif)
        PictureBox1.Image = My.Resources.ResourceManager.GetObject(pic)
        Me.Refresh()

        Sound = DirectCast(My.Resources.ResourceManager.GetObject("Tune"), MemoryStream)
        My.Computer.Audio.Play(Sound, AudioPlayMode.WaitToComplete)

        PictureBox1.Image = Nothing
        PictureBox1.Image = My.Resources.ResourceManager.GetObject("All_Done")
        Me.Refresh()
    End Sub
This sub' works.... playing the tune and showing the .gif file.
But the .gif doesn't 'run', it just shows the first frame. I added the 'Me.Refresh' to try to set it running (after PictureBox1.Refresh didn't work.) but that's not the answer.

Am I missing something? Another 'Imports' maybe?


Poppa.
 
Thanks John,


I'm sorry this reply is a bit tardy, I've had other issues.


Using a background thread has done the trick.


Poppa.
 
Back
Top