How to fade in fade out form in C#
By Tan Lee Published on Nov 05, 2024 366
To create a fade-in and fade-out effect for a form in C# Windows Forms, you can manipulate the Opacity property of the form.
To fade in the form, you can gradually increment the form's `Opacity` property in the `Form_Load` event using a `Timer`. This allows the form to transition from fully transparent to fully opaque over a specified period of time.
// Fade in private void Form_Load(object sender, EventArgs e) { this.Opacity = 0; while (this.Opacity < 1) { this.Opacity += 0.01; Thread.Sleep(15); // adjust this value for speed } }
To fade out the form, you can gradually decrement the form's `Opacity` property in the `Form_FormClosing` event using a `Timer`, allowing the form to transition from fully opaque to fully transparent before closing.
// Fade out private void Form_FormClosing(object sender, FormClosingEventArgs e) { this.Opacity = 1; while (this.Opacity > 0) { this.Opacity -= 0.01; Thread.Sleep(15); } }
- Primitive types in C#
- How to set permissions for a directory in C#
- How to Convert Int to Byte Array in C#
- How to Convert string list to int list in C#
- How to convert timestamp to date in C#
- How to Get all files in a folder in C#
- How to use Channel as an async queue in C#
- Case sensitivity in JSON deserialization
Categories
Popular Posts
Horizon MUI Admin Dashboard Template
Nov 18, 2024
Elegent Material UI React Admin Dashboard Template
Nov 19, 2024
Dash UI HTML5 Admin Dashboard Template
Nov 18, 2024
Material Lite Admin Template
Nov 14, 2024