Form Fade Effect in WinForms: Adding simple animations in your desktop can enhance the user experience. You can add simple animations just by using simple programming tricks like Form Fade Effect in WinForms when opening or closing of your form.
- Visual Studio 2010 or Later version.
Steps to Follow:
- If you have already created a windows forms applications project the skip to step 2. Or just create a brand new Windows forms application project in VS.
- Go to the design view of your form in which you want to add this simple Form Fade Effect. Add a timer control from the toolbox.
- For this tutorial we’ll just add this effect on closing of our form. But you can add this effect during opening of your form.
- Just go to the timer_tick event of the timer control and add the following code
if (this.Opacity > 0.0)
this.Opacity -= 0.025;
- Go to the OnClick event of the closing button. If you are not using the default closing button of WinForms. If you are using default layout, just select your form and goto OnClose event. And just call the start method of timer control like,
In the above technique, you noticed that we are just reducing the value of Opacity property of form. When tick event of timer occurs it reduces the opacity of form. Hence we’ve added simple form fade effect by using a simple technique.
Now you can try this technique to add the same effect on form opening event just by changing -= sign into +=. And call the start method on Form_Load event instead of form_Closing event. Also don’t forget to change greater than sign to less than in if condition.
Watch this short video to learn how to add Form Fade Effect
in WinForms using this technique.
I hope You’ve enjoyed this Tutorial. Please don’t forget to subscribe our Official YouTube Channel C# Ui Aacdemy.