C# 弹出窗体时背景窗体透明度切换

使用一个静态的方法,传入要显示的窗体就可以将母窗体的透明度调整为0.75

public static void ShowDialog(Form forms)
{
Form formBackground = new Form();
try
{
formBackground.StartPosition = FormStartPosition.CenterParent;
formBackground.FormBorderStyle = FormBorderStyle.None;
formBackground.Opacity = 0.75;
formBackground.BackColor = Color.Gray;
formBackground.WindowState = FormWindowState.Maximized;
formBackground.Show();
forms.Owner = formBackground;
forms.ShowDialog();
formBackground.Dispose();
}
catch (Exception)
{

            throw;
        }
    }

C# 弹出窗体时背景窗体透明度切换_第1张图片

你可能感兴趣的:(C#软件编写)