I’m trying to make text in a label flash on screen when a button is pressed and am having problems…
It seems a straight forward thing to do using the Label1.TextColor property but I cant seem to make it work
Any takers?
Platform? How are you going about it currently? Remember that interface updates don’t happen until the end of a method, so if you’re not using a timer your interface updates are happening all at once so it’s blinking faster than you see.
Without knowing the specifics of your usage, I have to recommend against flashing text for multiple accessibility reasons.
[quote=299272:@Tim Parnell]Platform? How are you going about it currently? Remember that interface updates don’t happen until the end of a method, so if you’re not using a timer your interface updates are happening all at once so it’s blinking faster than you see.
Without knowing the specifics of your usage, I have to recommend against flashing text for multiple accessibility reasons.[/quote]
Platform - MAC Desktop
Im using for and next loops to slow down the colour change between 2 colours (without any luck)
Its just a slow flash Im looking for in order to get the attention of the user
That’s your problem right there. Interface updates don’t happen until the end of the method, so all of the on and off you set during the loop happens all at once and you only see the end result. Set it up with a timer.
For next is an old fashion programming style totally unusable on an event driven platform for what you want to do.
The UI is updated only at the end of the event, so whatever you do in your for next will never show.
What you may want to try is to change the color in the button Keydown event, and put it back in Action event. But since the flash will be the length of the user click, it may be too fast to see.
Better way to proceed, is to use a timer. Code coming.
- Drag a Timer onto the window.
- Set its period to 200
- Set its mode to Off
- In its Action event :
[code]Sub Action() Handles Action
static count as integer
select case count
case 0
Label1.TextColor = &cFFFF0000
case 1
Label1.TextColor = &c00000000
me.Mode = Timer.ModeOff
Count = 0
Return
end select
count = count + 1
End Sub
[/code]
- In the button MouseDown event :
Function MouseDown(X As Integer, Y As Integer) Handles MouseDown as Boolean
Timer1.Mode = Timer.ModeMultiple
End Function
Voil. Blink yellow for 1/5th a second.
or best way is to creat a subclass of label with its own timer, and a Flash (on/off) property
It could also be done as a Label clever subclass
Edit: Dave just beat me to it.
Indeed, if he needs to blink often. He can even add a Blink as Boolean
computed property, like in the distant path Dos computers or VT100 terminals did blink.
Thanks everybody - WORKING
I am trying to make the subclass I mentioned… and guess I don’t understand something
// Calling the overridden superclass constructor.
Super.Constructor
zTimer=New Timer()
zTimer.Mode=timer.ModeOff
zTimer.period=250
zDisplayMode=false
zFlashColor=&CFF0000 // red
zTextColor = self.TextColor
AddHandler zTimer.Action, AddressOf Blink
Shouldn’t this (addHandler) cause method BLINK to be called every 1/4 second?
Blink is
Sub BLINK(send as Timer)
zDisplayMode=Not zDisplayMode
If zDisplayMode Then
Self.TextColor=&cff0000 //zFlashColor
Else
Self.TextColor=&c00ff00 //zTextColor
End If
Self.Refresh
End Sub
actually it IS… but same as OP, no refresh (and Invalidate is same)
there is a button action that turns the timer on/off
What is zDisplayMode ? What is it supposed to do ?
Look at BLINK
blink IS changing the colors, but not updating the screen…
the strange thing is when it should be blinking the text is “gold”, when I stop it (shut off timer), it comes up red or green depending on what zDisplaymode was when the timer stopped
Working for me. And don’t need a Refresh or Invalidate, changing textcolor automatically causes a redraw.
Here is my subclass
https://dl.dropboxusercontent.com/u/17407375/LabelBlink.xojo_binary_project
[quote=299301:@Michel Bujardet]Here is my subclass
https://dl.dropboxusercontent.com/u/17407375/LabelBlink.xojo_binary_project[/quote]
well mine is almost identical to your, with a few extra whistles and bells
and Michel… yours won’t run for me at all… NilException in Blink SET, but I can’t find how/where/why that is called before Timer is intialized
// FIX
if TimerBlink=nil then return
if value then
TimerBlink.Mode = Timer.ModeMultiple
else
TimerBlink.Mode = Timer.ModeOff
end if
it crashes on Linux
Public Property Blink as Boolean
[code]Set
if value then
TimerBlink.Mode = Timer.ModeMultiple
else
TimerBlink.Mode = Timer.ModeOff // crash here
end if
End Set
End Property[/code]
See my flashing text in action here - on the 5th number
http://www.real-soft.co.uk/resources/MAC-Bingo.dmg
(by the way - the reason it flashes on the 5th number is to remind the bingo caller to repeat the first 5 numbers gone)
I just corrected my class. The nil exception was due to the computed property initializing too early.
https://dl.dropboxusercontent.com/u/17407375/LabelBlink.xojo_binary_project
Thanks, it’s working now.