Alpha blending forecolor

Antoine

Regular
Joined
Aug 12, 2003
Messages
58
Location
The Netherlands
Dear all,

In VB.NET Pro 2003 I always managed to make the forecolor of a label control nicely fade into the background using
Code:
lblSomething.Forecolor = Color.FromArgb(a, 255, 255, 255)
Where a is counted up or down to get a nice smooth fading effect. BUT now in VB.NET Express 2005 this code doesn't work anymore ??? I tried several options, like transparent backcolor, and the Usecompatibletextrendering but nothing works. The text simply stays opaque. The color is changeable though if I edit the red/green/blue values, but the alpha value doesn't do anything.

I can use the opacity function with forms though, so it's not a video driver issue imho.

Thanks in advance !
Regards
Antoine :)
 
Interesting... at the moment the only solution I can think of is calculating the color resulting from the combination of the backcolor and semi-transparent forecolor yourself, i.e.:
Visual Basic:
'Calculate solid color resulting from an alpha blend
Public Function SolidColorFromAlphaBlend(ForeColor As Color, BackColor As Color) As Color
    'Strength of forecolor as a fraction between 0 and 1
    Dim Alpha As Single = CType(ForeColor.A / 255, Single)
    'Strength of backcolor
    Dim Omega As Single = 1-Alpha
  
    'Determing the resulting R, G, and B colors based on the 
    'strength of the component colors, as derived from alpha component
    Byte NewR = CByte(Math.Min( 'Math.Min ensures no overflow resulting from roundoff error.
        ForeColor.R * Alpha + BackColor.R * Omega, 255)
    Byte NewG = CByte(Math.Min(
        ForeColor.G * Alpha + BackColor.G * Omega, 255)
    Byte NewB = CByte(Math.Min(
        ForeColor.B * Alpha + BackColor.B * Omega, 255)
 
    Return Color.FromARGB(255, NewR, NewG, NewB)
End Function
I haven't tested this, and it won't work on top of a background image, but this function would help if the text were on top of a solid background.
 
Hello marble eater

Something like that I was also thinking of, the text itself is indeed on top of a grey (system color) background. But still I think it is strange. Maybe I didn't install framework correctly ? In .NET 2003 this work fluently :)
 
I have the same problem too. I highly doubt that it is a problem with your installation. It could be a graphics hardware compatability, but I doubt that too. Most likely, intentionally or not, they changed the behavior of the control.
 
Back
Top