C# – Popup Form with Fade Background in Windows Forms Application

Many viewers requested for a tutorial on Popup Form with Fade Background like a web application in windows forms application C#. So, Here I’m back with a short tutorial on how to create a Popup Form with Fade Background in winForms app C#.

We will be using an instance of Form class to become a background overlay of our Popup Form. We’ll also set the background form as an owner of Popup Form. Lets get started.

Tools Required:

  1. Visual Studio 2010 or later version.

Steps to Follow:

  1. First of all open up the Visual Studio.
  2. Create a brand new Windows Form Application project on it, or if you have an existing WinForm App project, just skip this step.
  3. Go to the Solution Explorer and add two new forms into projects by right clicking on the project file->Add->Form (Windows Form).
  4. One Form will be the parent and the other form will work as a popup form, so add a button control in the parent Form from the toolbox.
  5. Open the design view of your Popup Form and go to properties and set the TopMost property to True.
  6. Let say, We’ve named the parent Form as ‘Form1‘ and the popup form as ‘SubForm‘. Now go to the onClick event of the button (on parent form) and add the following Code.
Form formBackground = new Form();
            try
            {
                using (SubForm uu = new SubForm())
                {
                    formBackground.StartPosition = FormStartPosition.Manual;
                    formBackground.FormBorderStyle = FormBorderStyle.None;
                    formBackground.Opacity = .50d;
                    formBackground.BackColor = Color.Black;
                    formBackground.WindowState = FormWindowState.Maximized;
                    formBackground.TopMost = true;
                    formBackground.Location = this.Location;
                    formBackground.ShowInTaskbar = false;
                    formBackground.Show();

                    uu.Owner = formBackground;
                    uu.ShowDialog();

                    formBackground.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                formBackground.Dispose();
            }

Video Tutorial:

Watch this full video tutorial for a clear concept and demonstration.

Video Tutorial

Source Code:

Note: The source code provided in the above link may be different from the project which was demonstrated in the video because it was a project created for one of our valuable clients, but the main code for a background overlay is available in the attached zip file.

I hope you enjoyed the tutorial. Please don’t forget to subscribe our Official YouTube Channel C# Ui Academy

One thought on “C# – Popup Form with Fade Background in Windows Forms Application

  • May 22, 2020 at 1:59 pm
    Permalink

    Hi!

    What to modify in the code above if I want to fade (blur) the parent (main) form only and not the whole screen?
    Because FormWindowState doesn’t have to many properties?

    Thank you!

    Reply

Leave a Reply

You have to agree to the comment policy.