Results 1 to 14 of 14

Thread: [RESOLVED] Fading out an Image or using a .gif image

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Resolved [RESOLVED] Fading out an Image or using a .gif image

    I need to be able to fire the fading of an image or the playing of a .gif image from a button to a picturebox.

    Is this possible in vb? I have tried googling it but I can't find anything of relevance to vb.

    I need it to work on another form, but I can figure that part out just need to find a way to introduce an image at 100% opacity, then slowly lower that to reveal what under it.

    Ideally though I would want to play a .gif file each time the button is pressed that would cover the area and then when finished reveal it.

    Any ideas?
    Last edited by Noob script kiddie; Dec 1st, 2010 at 05:15 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Fading out an Image or using a .gif image

    that wouldn't work because pictureboxes don't offer transparency. you could reduce the opacity of your image but ultimately all you'd reveal is the background of the picturebox.

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Fading out an Image or using a .gif image

    Hi Noob sk,

    I think Paul is assuming you need to show other controls through the image. It can be done, but you need to use a separate form to hold the image - see for example the "Slide Show with Cross Fading" in my signature.

    On the other hand, if you only want to show a plain background or even another image under the fading image, it's possible to do it on a Form or a PictureBox. If you want details about that method, let me know.

    BB

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Re: Fading out an Image or using a .gif image

    The idea is to use an image to cover a textbox. The textbox having a number inside of it. So the fading of the image would be a way to "reveal" the number to the viewer in a stylish way.

    So maybe Paul is correct?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Re: Fading out an Image or using a .gif image

    Alright so your idea of using another form sparked an idea my end and I think I have done it!

    Just used a third form which loads up once the generate button is clicked, set an image as background and added a 4 second sleep. After the 4 seconds is up i just used Form3.Close () and wallah! Number appears.

    Only downfall, the sleep command stops the animated .gif from working

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Fading out an Image or using a .gif image

    Quote Originally Posted by Noob script kiddie View Post
    Only downfall, the sleep command stops the animated .gif from working
    That sounds like a problem that could be solved. Maybe you should use a timer instead of Sleep, but it's hard to say without seeing your code. BB

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Re: Fading out an Image or using a .gif image

    The code for my button labelled Generate

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim list As New ArrayList
    3.  
    4.         Dim Low As Integer = 1
    5.         Dim High As Integer
    6.         High = TextBox1.Text
    7.         Low = TextBox2.Text
    8.  
    9.         For i As Integer = Low To High
    10.             'Add the numbers to the collection.
    11.             list.Add(i)
    12.         Next i
    13.  
    14.         Dim rand As New Random
    15.         Dim index As Integer
    16.         Dim item As Object
    17.  
    18.         'Display the items in random order.
    19.         'While list.Count > 0
    20.         'Choose a random index.
    21.         index = rand.Next(0, list.Count)
    22.  
    23.         'Get the item at that index.
    24.         item = list(index)
    25.  
    26.         'Remove the item so that it cannot be chosen again.
    27.         list.RemoveAt(index)
    28.  
    29.         'Display the item.
    30.         TextBox3.Text = item.ToString
    31.         ListBox1.Items.Add(TextBox3.Text)
    32.         'End While
    33.         Form3.Show()
    34.         Threading.Thread.Sleep(4000)
    35.         Form3.Close()
    36.     End Sub

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Re: Fading out an Image or using a .gif image

    I added all of that code to my button, but its not closing form3.

    Then I reread your post and it looks like the second half of the code is in the timer sub?



    vb Code:
    1. 'Display the item.
    2.         TextBox3.Text = item.ToString
    3.         ListBox1.Items.Add(TextBox3.Text)
    4.  
    5.         'End While
    6.         Form3.Show()
    7.         WaitCounter = 4000
    8.         tmrWait.Interval = 50
    9.         tmrWait.Start()
    10.  
    11.         'Threading.Thread.Sleep(6000)
    12.         'Form3.Close()
    13.         WaitCounter = WaitCounter - tmrWait.Interval
    14.         If WaitCounter <= 0 Then
    15.             tmrWait.Stop()
    16.             Form3.Close()
    17.         End If
    18.  
    19.     End Sub


    * Added code to the timer sub, still wont close the form.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Re: Fading out an Image or using a .gif image

    So this is how it is at the moment:

    Code for the timer sub
    vb Code:
    1. Private Sub tmrWait_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrWait.Tick
    2.         Dim tmrWait As New Timer
    3.         Dim WaitCounter As Integer
    4.  
    5.         WaitCounter = WaitCounter - tmrWait.Interval
    6.         If WaitCounter <= 0 Then
    7.             tmrWait.Stop()
    8.             Form3.Close()
    9.         End If
    10.  
    11.     End Sub

    And the code attached to the bottom of my button:
    vb Code:
    1. Form3.Show()
    2.         WaitCounter = 4000
    3.         tmrWait.Interval = 50
    4.         tmrWait.Start()
    5.  
    6.  
    7.     End Sub

    Now when I click on the button form3 flashes for a second, but then quickly disappears. Frustrating I don't know what to change !

    The properties for the timer I changed to "Enabled - True" and "Interval - 1000" from which I read was about 1 second.

  10. #10
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Fading out an Image or using a .gif image

    It's unnecessarily complicated and it won't work anyway. You could add the Timer in the Designer and set its interval to 4000. But if instead you want to add it in the code, you have to declare it at Form level (not in its own Tick sub!) with the WithEvents keyword. Otherwise it won't tick!
    Code:
    Dim WithEvents tmrWait As New Timer
    You don't need that WaitCounter at all. In your button click sub you could put this:
    Code:
    Form3.Show
    tmrWait.Interval = 4000
    tmrWait.Start
    And in the tmrWait_Tick sub you only need one line:
    Code:
    Form3.Hide
    If your animation doesn't run now, there must be some other reason for it. (Maybe you know you have to put it in a PictureBox for it to run automatically.)

    BB

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Re: Fading out an Image or using a .gif image

    Sweet it seems all go now. Added this to the tick sub, dont know if it actually helps but its working now so I ain't removing it

    vb Code:
    1. tmrWait.Stop()

    Thanks for all the help!

  12. #12
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Fading out an Image or using a .gif image

    Quote Originally Posted by Noob script kiddie View Post
    vb Code:
    1. tmrWait.Stop()
    Yes, I thought about that. It's technically not necessary because the timer period starts again from scratch when you (re)start it, but it looks logical. BB

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Re: [RESOLVED] Fading out an Image or using a .gif image

    Right now for some reason I don't think that my timer is stopping. You see when I click my generate button it says this :
    vb Code:
    1. tmrWait.Stop()
    2.            Form3.Show()
    3.         tmrWait.Start()

    And my ticker sub says this:

    vb Code:
    1. Form3.Close()
    2.         tmrWait.Stop()

    But I;m pretty sure that my ticker isnt actually stopping, it is continuing to tick at 5000(interval).

    I say this because after I click generate, my form appears, waits, then closes. If I click generate straight again, it opens form, waits, closes. However if I wait a bit in between clicking generate, mid way through my animation the form closes. So that has led me to believe that my ticker is continuously ticking.

    Is there anything I can add to ensure it stops?

    I thaught for sure tmrWait.Stop() in the ticker sub would mean it would stop after every tick.. but I guess not

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    141

    Re: Fading out an Image or using a .gif image

    So I think I may have solved it? Not sure though so will post back if not..

    Basically I was referring to tmrWait, yet my sub was Ticker 1. I changed everything over to Ticker 1 and got rid of any connection with tmrWair. It seems to be working now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width