Results 1 to 4 of 4

Thread: Making a Object Fade in and out on command.

  1. #1

    Thread Starter
    Addicted Member Reapism's Avatar
    Join Date
    Sep 2012
    Posts
    170

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

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,389

    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).
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    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

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Making a Object Fade in and out on command.

    Clever!

    vb.net Code:
    1. Public Class Form1
    2.     Dim alpha As Integer = 0
    3.     Dim increment As Integer = 8
    4.  
    5.     Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    6.         Label1.BackColor = Color.FromArgb(alpha, Color.FromKnownColor(KnownColor.Control))
    7.         alpha += increment
    8.         If alpha = 240 OrElse alpha = 0 Then
    9.             increment = increment * -1
    10.         End If
    11.     End Sub
    12. End Class
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width