How to fade in fade out form in C#
By FoxLearn 11/5/2024 12:20:39 PM 59
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); } }
- How to get application folder path in C#
- How to copy data to clipboard in C#
- How to mark a method as obsolete or deprecated in C#
- How to Call the Base Constructor in C#
- Deep Copy of Object in C#
- How to Catch Multiple Exceptions in C#
- How to cast int to enum in C#
- What is the difference between String and string in C#?
Categories
Popular Posts
SB Admin Template
11/17/2024
RuangAdmin Template
11/17/2024
DASHMIN Admin Dashboard Template
11/17/2024
K-WD Tailwind CSS Admin Dashboard Template
11/17/2024