Making a Object Fade in and out on command.
I would like to switch opacity of a button and list box on command. I know there are ways of doing it with picture boxes but is their a way without. If so may someone share the knowledge!
Instead of bland visible property Boolean = true/false
If anything making it look like its fading, I always reach out to you brilliant coders, I really appreciate this.
Re: Making a Object Fade in and out on command.
It can be done pretty easily in WPF the XAML would look something like this:
Code:
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:0.2"/>
But in winforms I don't know if it can be done without using DirectX or XNA, unless there's a class that I don't know about(which is very possible).
Re: Making a Object Fade in and out on command.
I can think of a trick to do this in WinForms. Position a Label exactly over the button; set the Label's Parent property to the button, its location to (0,0), and its backcolor to Transparent. To fade the button out, fade the Label's backcolor from Transparent to the BackColor of the form (or better, 99% of the backcolor of the Form to avoid a slight jerk); and the reverse to fade it back in.
BB
Re: Making a Object Fade in and out on command.
Clever! :cool:
vb.net Code:
Public Class Form1
Dim alpha As Integer = 0
Dim increment As Integer = 8
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Label1.BackColor = Color.FromArgb(alpha, Color.FromKnownColor(KnownColor.Control))
alpha += increment
If alpha = 240 OrElse alpha = 0 Then
increment = increment * -1
End If
End Sub
End Class