[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?
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.
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
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?
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 :(
Re: Fading out an Image or using a .gif image
Quote:
Originally Posted by
Noob script kiddie
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
Re: Fading out an Image or using a .gif image
The code for my button labelled Generate
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim list As New ArrayList
Dim Low As Integer = 1
Dim High As Integer
High = TextBox1.Text
Low = TextBox2.Text
For i As Integer = Low To High
'Add the numbers to the collection.
list.Add(i)
Next i
Dim rand As New Random
Dim index As Integer
Dim item As Object
'Display the items in random order.
'While list.Count > 0
'Choose a random index.
index = rand.Next(0, list.Count)
'Get the item at that index.
item = list(index)
'Remove the item so that it cannot be chosen again.
list.RemoveAt(index)
'Display the item.
TextBox3.Text = item.ToString
ListBox1.Items.Add(TextBox3.Text)
'End While
Form3.Show()
Threading.Thread.Sleep(4000)
Form3.Close()
End Sub
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:
'Display the item.
TextBox3.Text = item.ToString
ListBox1.Items.Add(TextBox3.Text)
'End While
Form3.Show()
WaitCounter = 4000
tmrWait.Interval = 50
tmrWait.Start()
'Threading.Thread.Sleep(6000)
'Form3.Close()
WaitCounter = WaitCounter - tmrWait.Interval
If WaitCounter <= 0 Then
tmrWait.Stop()
Form3.Close()
End If
End Sub
* Added code to the timer sub, still wont close the form.
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:
Private Sub tmrWait_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrWait.Tick
Dim tmrWait As New Timer
Dim WaitCounter As Integer
WaitCounter = WaitCounter - tmrWait.Interval
If WaitCounter <= 0 Then
tmrWait.Stop()
Form3.Close()
End If
End Sub
And the code attached to the bottom of my button:
vb Code:
Form3.Show()
WaitCounter = 4000
tmrWait.Interval = 50
tmrWait.Start()
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.
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:
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
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 :)
Thanks for all the help!
Re: Fading out an Image or using a .gif image
Quote:
Originally Posted by
Noob script kiddie
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
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:
tmrWait.Stop()
Form3.Show()
tmrWait.Start()
And my ticker sub says this:
vb Code:
Form3.Close()
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
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.