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.
Tools Required:
- 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;
}
else
{
timer1.Stop();
Application.Exit();
}
- 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,
timer1.Start();
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.
Video Tutorial:
Watch this short video to learn how to add Form Fade Effect
in WinForms using this technique.
Source Code:
I hope You’ve enjoyed this Tutorial. Please don’t forget to subscribe our Official YouTube Channel C# Ui Aacdemy.
Hi there! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us valuable information to work on. You have done a wonderful job!
Hi there,I was really looking for a detailed step by step guide to do this because I was really confused about doing this.Thanks a lot, buddy.Keep posting good stuff. Cheers.