Flashing Label

johnadonaldson

Well-known member
Joined
Nov 9, 2005
Messages
48
Programming Experience
10+
How do I make a Label Flash. What I want to do is have a Label Flash on command. Such as when I am updating data, I want to make a Label visible and have it Flash until the updating is complete, then I will make it invisible.
 
Well this might be a long way round but labels can play animated gifs without having to add any code. So i suppose one way would be to do your update command on a asyncronus delegate. Create a flashing animated gif and set it as an emmbedded resource in your project. Then before calling begininvoke on your delegate set the labels image to the animated gif using the system.reflection.getmanifestresourcestream method. Then on the asynchronus callback you can set the labels image property to nothing. Dont forget to check to see if an invoke is required before affecting controls that may not have been created on the same thread. Sorry if this is a bit complicated but it's the only way i can think of right now, and it's pretty late here so my brain is getting a bit tired.

Hope this helps a bit.
 
If you don't want to create an image ahead of time, all you need to do is add a Timer to your form and place this code in its Tick event:
VB.NET:
myLabel.Visible = Not myLable.Visible
This will toggle the Label's Visible property each time the Timer Ticks, so you just set the Timer's Interval so you get the flashing speed that you want.
 
Thanks for the feedback. A friend of mine sent me the same code too. Amazing how KISS it is once you figure it out.

DIM bBlink as Boolean

Private
Sub FlashTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlashTimer.Tick
'Blink Label
If bBlink Then
Me.Label185.Visible = Not Me.Label185.Visible
End If
End Sub
 
I'd be inclined to Start and Stop the Timer rather than leaving it running and testing a Boolean variable. It's not too resource intensive but why leave the Timer running when you know for a fact that it's not needed?
 
Back
Top