Fading the color of a label from 1 to the other

I have a very simple countdown timer that I made. I would like the color of the label (numbers) to change as the timer ticks. I want to start with Green and then fade(transition) to Red when the timer ticks 00:00.

The timer is working great, I can also get the label to change to red once the timer hits 00:00. I would like it to fade though. Here's is part of the code.

'handles the label ticking down'
Private Sub tmrCountdown_Tick(sender As Object, e As EventArgs) Handles tmrCountdown.Tick
    Dim ts As TimeSpan = TargetDT.Subtract(DateTime.Now)
    If ts.Milliseconds > 0 Then
        lblTime.Text = ts.ToString("mm\:ss")
        lblTime.ForeColor = Color.FromArgb(0, 255, 0)
    Else
        lblTime.ForeColor = Color.FromArgb(255, 0, 0) 'changes label color to red when it hits 00:00'
        'stops the timer once the label reaches 00:00
        lblTime.Text = "00:00"


        'Plays sound when timer hits 00:00'
        My.Computer.Audio.Play(My.Resources.alarm, AudioPlayMode.BackgroundLoop)
        tmrCountdown.Stop()

        End If
End Sub

I know this is an old thread, but I was looking for something like this with a label glowing red. To do this I created a timer and then set up some conditional counters to alter the RGB values of the label colour. The rate of change is set by the timer.interval value. Hope this helps someone.

Public Class AlertWindow

Dim Red As Integer = 0
Dim Green As Integer = 0
Dim Blue As Integer = 0
Dim CountUp As Boolean = True

Private Sub AlertWindow_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    Timer1.Enabled = True

End Sub

   Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

    If CountUp = True Then

        If Red < 253 Then
            Red = Red + 1
        Else
            CountUp = False
        End If

    End If

    If CountUp = False Then

        If Red > 0 Then
            Red = Red - 1
        Else
            CountUp = True
        End If

    End If

    Label1.ForeColor = Color.FromArgb(Red, Blue, Green)

End Sub

End Class

Learn Unity3D Programming with UnityScript: Unity's JavaScript for , Lerp(1, 0, fading); GUI.Label(Rect(0, 0, 250, 25), "Press C to crouch or Space to jump"); } Breaking this Declare a reference variable fadingColor of type Color  By fade I mean, it starts as one color and transitions to the other. So it goes from solid green to solid red. – MrGerrm Sep 3 '14 at 20:51 well then, just decrease the Green value and increase the Red value used in your color maker as time closes in on 0.

For Fade in you can use Alpha parameter

for example:

Static Alpha As Integer

    lblTime.BackColor = Color.FromArgb(Alpha , 255, 0, 0)

    Alpha  += 5 'amount of opacity change for each timer tick
    If Alpha  > 255 Then lblTime.Enabled = False 'finished fade-in

Aynchronous Color Fading, vote 1vote 2vote 3vote 4vote 5 This provides an easy way to fade any color property asynchronously. shared method for asynchronously fading a color property from one color to another. For example, a text box or label. One common reason for color fading is bleaching. Bleaching may happen naturally from sun exposure, or it can happen from exposure to the chemical form of bleach. Other reasons for color fading can be from too hot of water during laundering, or not following recommended care guidelines for the specific type of fabric.

This works better when you can average the colors together.

You have to work out what value you want for the tickCount based on your timer interval:

Private tickCount As Integer = 100
Private tickValue As Integer = 0

Private Sub tmrCountdown_Tick(sender As Object, e As EventArgs) _
                              Handles tmrCountdown.Tick
  If tickValue > tickCount Then
    tmrCountdown.Stop()
    tickValue = 0
  Else
    lblTime.ForeColor = AvgColor(Color.Green, Color.Red, tickValue, tickCount)
    tickValue += 1
  End If
End Sub

Private Function AvgColor(startColor As Color,
                          finalColor As Color,
                          colorValue As Integer,
                          colorCount As Integer) As Color
  Dim r1 As Integer = startColor.R
  Dim g1 As Integer = startColor.G
  Dim b1 As Integer = startColor.B

  Dim r2 As Integer = finalColor.R
  Dim g2 As Integer = finalColor.G
  Dim b2 As Integer = finalColor.B

  Dim avgR As Integer = r1 + ((r2 - r1) * colorValue) / colorCount
  Dim avgG As Integer = g1 + ((g2 - g1) * colorValue) / colorCount
  Dim avgB As Integer = b1 + ((b2 - b1) * colorValue) / colorCount

  Return Color.FromArgb(avgR, avgG, avgB)
End Function

HMM Dallas Music and Entertainment Memorabilia Auction Catalog #688, Label should display full, original color, but may have a spindle mark or two. NEAR MINT May exhibit slight fading of label color. Record There may be writing, non-major tears, stains, or other abuses. Corners 1:00 PM CT 39 Recordings. Creating a fade out label. It also handles labels of different colors (e.g. green, red) Asking for help, clarification, or responding to other answers.

'RGB_1 = Timer;
'RGB_2 = Timer;
'RGB_3 = Timer;
'Label1 = Label;
'RGB1 = Progressbar;
'RGB2 = Progressbar;
'RGB3 = Progressbar.



Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    RGB1.Value = 255
    RGB_1.Interval = 10
    RGB_2.Interval = 10
    RGB_3.Interval = 10
RGB_1.Start()
End Sub

Private Sub RGB_1_Tick(sender As Object, e As EventArgs) Handles RGB_1.Tick
    If RGB2.Value = 255 Then
        If RGB1.Value = 0 Then
            If RGB3.Value = 255 Then
                RGB_1.Stop()
                RGB_2.Start()
            Else
                RGB3.Value += 1
            End If
        Else
            RGB1.Value -= 1
        End If
    Else
        RGB2.Value += 1
    End If
    SetColor()
End Sub

Private Sub RGB_2_Tick(sender As Object, e As EventArgs) Handles RGB_2.Tick
    If RGB3.Value = 255 Then
        If RGB2.Value = 0 Then
            If RGB1.Value = 255 Then
                RGB_2.Stop()
                RGB_3.Start()
            Else
                RGB1.Value += 1
            End If
        Else
            RGB2.Value -= 1
        End If
    Else
        RGB3.Value += 1
    End If
    SetColor()
End Sub

Private Sub RGB_3_Tick(sender As Object, e As EventArgs) Handles RGB_3.Tick
    If RGB3.Value = 0 Then
        RGB_3.Stop()
        RGB_1.Start()
    Else
        RGB3.Value -= 1
    End If
    SetColor()
End Sub

Sub SetColor()
    Label1.ForeColor = Color.FromArgb(RGB1.Value, RGB2.Value, RGB3.Value)
End Sub

Michael Broadbent's Vintage Wine: Fifty Years of Tasting Three , Most recently, two bottles, one oxidised, the other losing colour but lively; there a very good old thoroughbred stables nose; dry, faded yet still retaining vestiges of Most recently, with Pillet-Will label, recorked in 1 991: on the pale side; old,  This is the problem I have with Dymo Letratag labels fading after a while. I've set this video to 1280x720 (HD) and so that you may better see the difference between year or two old labels and

United States Congressional serial set, 1 . The size and typography of the label are of the greatest importance. one line to another, and so broken into paragraphs as to separate from each other the topics Much attention should be given to the selection of type and color for labels, can not be used because of their tendency to fade, objectionable in itself and  script.Parent.Mesh.VertexColor = col; wait(0.03); end fading = false; -- Let everyone know -- that we can start fading again end This solution has other limitations, unfortunately. If you use a mesh, you won't be able to see the material of a part, or any of its surfaces.

Report Upon the Condition and Progress of the U.S. National Museum , 1 . The size and typography of the label are of the greatest importance . line to another , and so broken into paragraphs as to separate from each other the topics Much attention should be given to the selection of type and color for labels , it can not be used because of their tendency to fade , objectionable in itself and  A gradient fill is a shape fill that gradually changes from one color to another across the surface of the shape. A shape fill that gradually changes between three colors It can be a variation of one color as shown above, or a blending of two or more different colors to create stunning effects like the examples below. Preset Horizon gradient fill

A Memorial of George Brown Goode: Together with a Selection of His , 1. The size and typography of the label are of the greatest importance. one line to another, and so broken into paragraphs as to separate from each other the topics Much attention should be given to the selection of type and color for labels, can not be used because of their tendency to fade, objectionable in itself and  An additional benefit of thermal transfer printing is the ability to print in color. With the purchase of a colored ribbon, you can print a logo, graphic, or text in the color of your ribbon. The color isn't specific to a graphic or individual block of text, however, the color applies to your entire label.

Comments
  • by fade do you mean a gradient? its easier just to define "bands" where the value translates to Red/Yellow/Green; also some in-between colors arent very intuitive.
  • By fade I mean, it starts as one color and transitions to the other. So it goes from solid green to solid red.
  • well then, just decrease the Green value and increase the Red value used in your color maker as time closes in on 0. that is called a gradient.
  • Ok, I'm not sure how to go about doing that. Could you provide an example?
  • just calculate a value for this: Color.FromArgb(r, g, 0) start r as zero and make it larger each time the timer ticks, g does the inverse: starts as 255 and gets smaller on each tick.
  • I just logged into this account for the first time in a long time and saw your answer. I no longer needed this but thank you for answering. I tried it and great solution :)
  • That definitely works but is there a way to get it to change the color of the text and not the square box? I tried changing Back.Color to Fore.Color but it didn't work T_T
  • unfortunately alpha parameter not work for fore color, for walk around solution you can use lblTime.ForeColor = Color.FromArgb(0, 255, 255 - alpha, 255 - alpha) .
  • That works really great! It gives me an error though once Alpha is out of numbers lblTime.ForeColor = Color.FromArgb(0, 0 + Alpha, 255 - Alpha, 0) That is what I have, it's going from Green to Red like I want but when it gets to Red 255 then it gives an error and says: "Value of '260' is not valid for 'red'. 'red' should be greater than or equal to 0 and less than or equal to 255."
  • the color range between 0-255 because of that you must check if (alpha>255) and you want to check if ((255-alpha)<0)