# Make text in a label flash

**URL:** <https://forum.xojo.com/t/make-text-in-a-label-flash/34567>\
**Category:** General\
**Created:** [November 20, 2016, 6:58pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567 "2016-11-20T18:58:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stuart\_Sykes](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@Stuart\_Sykes](https://forum.xojo.com/u/Stuart_Sykes)\
**Post date:** [November 20, 2016, 6:58pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/1 "2016-11-20T18:58:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [November 20, 2016, 7:01pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/2 "2016-11-20T19:01:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stuart\_Sykes](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@Stuart\_Sykes](https://forum.xojo.com/u/Stuart_Sykes)\
**Post date:** [November 20, 2016, 7:03pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/3 "2016-11-20T19:03:44Z")

</div>

[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

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [November 20, 2016, 7:15pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/4 "2016-11-20T19:15:05Z")

</div>

> [@299274:@Stuart Sykes](#):
>
> Im using for and next loops to slow down the colour change between 2 colours (without any luck)

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.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 20, 2016, 7:17pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/5 "2016-11-20T19:17:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 20, 2016, 7:25pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/6 "2016-11-20T19:25:15Z")

</div>

- 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.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [November 20, 2016, 7:26pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/7 "2016-11-20T19:26:03Z")

</div>

or best way is to creat a subclass of label with its own timer, and a Flash (on/off) property

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [November 20, 2016, 7:26pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/8 "2016-11-20T19:26:15Z")

</div>

It could also be done as a Label clever subclass 😉

Edit: Dave just beat me to it.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 20, 2016, 7:27pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/9 "2016-11-20T19:27:46Z")

</div>

> [@299282:@Dave S](#):
>
> or best way is to creat a subclass of label with its own timer, and a Flash (on/off) property

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.

---

<div class="post-metadata">

**Author:** ![Stuart\_Sykes](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@Stuart\_Sykes](https://forum.xojo.com/u/Stuart_Sykes)\
**Post date:** [November 20, 2016, 7:29pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/10 "2016-11-20T19:29:23Z")

</div>

Thanks everybody - WORKING 🙂

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [November 20, 2016, 8:00pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/11 "2016-11-20T20:00:27Z")

</div>

I am trying to make the subclass I mentioned… and guess I don’t understand something

```auto
  // 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

```auto
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

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 20, 2016, 8:07pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/12 "2016-11-20T20:07:31Z")

</div>

What is zDisplayMode ? What is it supposed to do ?

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [November 20, 2016, 8:08pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/13 "2016-11-20T20:08:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Will\_Shank](https://forum.xojo.com/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@Will\_Shank](https://forum.xojo.com/u/Will_Shank)\
**Post date:** [November 20, 2016, 8:21pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/14 "2016-11-20T20:21:53Z")

</div>

Working for me. And don’t need a Refresh or Invalidate, changing textcolor automatically causes a redraw.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 20, 2016, 8:24pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/15 "2016-11-20T20:24:04Z")

</div>

Here is my subclass

[https://dl.dropboxusercontent.com/u/17407375/LabelBlink.xojo\_binary\_project](https://dl.dropboxusercontent.com/u/17407375/LabelBlink.xojo_binary_project)

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [November 20, 2016, 8:30pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/16 "2016-11-20T20:30:54Z")

</div>

[quote=299301:@Michel Bujardet]Here is my subclass

[https://dl.dropboxusercontent.com/u/17407375/LabelBlink.xojo\_binary\_project[/quote]](https://dl.dropboxusercontent.com/u/17407375/LabelBlink.xojo_binary_project%5B/quote%5D)  
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

```auto
// FIX 
  if TimerBlink=nil then return
  if value then 
    TimerBlink.Mode = Timer.ModeMultiple
  else
    TimerBlink.Mode = Timer.ModeOff
  end if
```

---

<div class="post-metadata">

**Author:** ![Axel\_Schneider](https://forum.xojo.com/user_avatar/forum.xojo.com/axel_schneider/32/465_2.png) [@Axel\_Schneider](https://forum.xojo.com/u/Axel_Schneider)\
**Post date:** [November 20, 2016, 8:33pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/17 "2016-11-20T20:33:06Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![Stuart\_Sykes](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@Stuart\_Sykes](https://forum.xojo.com/u/Stuart_Sykes)\
**Post date:** [November 20, 2016, 8:33pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/18 "2016-11-20T20:33:40Z")

</div>

See my flashing text in action here - on the 5th number 🙂  
[http://www.real-soft.co.uk/resources/MAC-Bingo.dmg](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) 🙂

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 20, 2016, 8:36pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/19 "2016-11-20T20:36:31Z")

</div>

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](https://dl.dropboxusercontent.com/u/17407375/LabelBlink.xojo_binary_project)

---

<div class="post-metadata">

**Author:** ![Axel\_Schneider](https://forum.xojo.com/user_avatar/forum.xojo.com/axel_schneider/32/465_2.png) [@Axel\_Schneider](https://forum.xojo.com/u/Axel_Schneider)\
**Post date:** [November 20, 2016, 8:40pm UTC](https://forum.xojo.com/t/make-text-in-a-label-flash/34567/20 "2016-11-20T20:40:29Z")

</div>

Thanks, it’s working now.

[Next page](https://forum.xojo.com/t/make-text-in-a-label-flash/34567.md?page=2)
