C# Form Fade In / Fade Out

This short tutorial is made to show you how to create a fade in / fade out effect for a form. Since basic Windows Forms doesn’t provide such an option, it must be done manually, by using code.
Note: we’ll use timers instead of general repetitive structures to avoid thread blocking

Fade in Effect

To do this, all we have to do is to set the Form’s Opacity to 0. Then, using a Timer we’ll slowly increase opacity. All this code should go in a event handler that is executed when the form loads.
As an example:


Fade Out Effect

This works the same way as the fade in effect: we’ll use a Timer that lowers the Opacity, that is started when the form is closing. The code should be added in the form-closing event handler.

Believe it or not, that’s all, however pay attention to the events so you won’t assign 2 event handlers to the same event.
Previous
Next Post »