Click here to Skip to main content
Licence CPOL
First Posted 8 Mar 2007
Views 13,415
Downloads 75
Bookmarked 14 times

Aynchronous Color Fading

By | 8 Mar 2007 | Article
This provides an easy way to fade any color property asynchronously.

Introduction

This is a simple class with a shared method for asynchronously fading a color property from one color to another. I needed a way to indicate to users that they had saved or deleted something, so I wanted a way to slowly fade the background color of a textbox.

Code Usage

There are three overloads of the shared method. The basic method takes seven parameters:

  • container - The object that contains the color property to be fading. For example, a text box or label.
  • colorProperty - The name of the color property to change - this has to be a string, for example, "ForeColor" or "BackColor".
  • startColor - The color that will begin the fade.
  • endColor - The color that will end the the fade.
  • steps - The number of steps to take in fading from the start color to the end color.
  • delay - A delay in milliseconds between each step in the fade.
  • callback - An optional function that will be called when the fade completes.

The second overload takes an intermediate color and the number of steps for fading, and the final overload takes a list of colors and steps.

Problem

I wanted to simply pass the color property itself, and pass it byRef so that I could change it, but I couldn't figure out how to do it. I don't know if you can pass a byRef parameter to another thread. Anyway, that's why the method requires a container object and the name of the property to change.

Examples

Dim textBox1 As New TextBox() 
Visual.FadeColor(textBox1, "BackColor", Color.Green, Color.White, _
                 25, 25, AddressOf DoneFading)

Private Sub DoneFading(ByVal container As Object, ByVal colorProperty As String)
    MsgBox("Done fading!")
End Sub

Conclusion

Overall, it's pretty simple, but hopefully useful. If you have any suggestions, feel free to let me know.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

nauthiz69_3



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAwesome PinmemberAcidRaZor3:33 16 May '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 8 Mar 2007
Article Copyright 2007 by nauthiz69_3
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid