BLOG.CSHARPHELPER.COM: Make a form fade out until it disappears in C#
Make a form fade out until it disappears in C#
A form's Opacity property determines how opaque it is. Opacity = 1 means the form is opaque and Opacity = 0 means the form is transparent. Values between 0 and 1 make a translucent form. (Note that at design time the Properties window displays Opacity values between 0% and 100% instead of between 0 and 1.)
When you click this example's Close button, the code enables a Timer control that reduces the form's Opacity until it disappears.
// Make the form disappear. private void btnClose_Click(object sender, EventArgs e) { tmrFade.Enabled = true; }
// Decrease the form's opacity by 20%. private void tmrFade_Tick(object sender, EventArgs e) { Opacity -= 0.2; if (Opacity <= 0) Close(); }
Comments