C# 在windows应用程序中打开弹出窗口时,是否可以生成阴影(禁用)类图像?

C# 在windows应用程序中打开弹出窗口时,是否可以生成阴影(禁用)类图像?,c#,windows,winforms,C#,Windows,Winforms,我不熟悉windows应用程序。使用C#和.NET。 我想要像我附加的图像一样的东西。当弹出窗口打开时,我希望mdi父页面被隐藏或取消锁定。(就像我们在web应用程序或Jquery弹出窗口中所做的那样) 有可能吗?如果是,我怎么做 请提供帮助。对于Microsoft Windows,实际上没有子窗口的概念。弹出窗口或模态/非模态对话框与任何其他窗口一样,它们可以放置在屏幕上的任何位置,因此可能超出您认为的父窗口的范围 有些web概念在桌面上无法正常工作 您可以通过使用Windows.Form的

我不熟悉windows应用程序。使用C#和.NET。 我想要像我附加的图像一样的东西。当弹出窗口打开时,我希望mdi父页面被隐藏或取消锁定。(就像我们在web应用程序或Jquery弹出窗口中所做的那样)

有可能吗?如果是,我怎么做


请提供帮助。

对于Microsoft Windows,实际上没有子窗口的概念。弹出窗口或模态/非模态对话框与任何其他窗口一样,它们可以放置在屏幕上的任何位置,因此可能超出您认为的父窗口的范围


有些web概念在桌面上无法正常工作

您可以通过使用
Windows.Form的不透明度属性来实现这一点
为此,请创建一个新窗体,设置其不透明度(例如:.75),并在显示子窗口时将其显示在父窗体上。
下面给出了一个例子

There are three windows used here
1. ParentForm
2. OverlayForm
3. ChildForm
1。家长表格

1. Create an instance of the Child form 
2. Create an Instance of the Overlayform, Pass the objects Instances of Child and Parent(current form) as a parameter to the Constructor
3. Then Show the OverLay Form by using  ShowDialog Method.

Code:

public partial class ParentForm : Form
{
    public ParentForm()
    {

        InitializeComponent();
    }

    private void ParentForm_Load(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        ChildForm child1 = new ChildForm();
        // Create a new form.
        OverlayForm form2 = new OverlayForm(this, child1);
        child1.OverLay = form2;
        // Display the form as a modal dialog box.
        form2.ShowDialog(this);
    }
}
1. In the constructor store the childForm and ParentForm object in a local variables. 
       And Set the The properties (like width,height) to the Overlay Window
    2. In the OverlayForm_Load show the ChildForm window.

public partial class OverlayForm : Form
{
    public Form ParentForm { get; set; }
    public Form child { get; set; }
    public OverlayForm(Form parent, Form child)
    {
        InitializeComponent();
        this.child = child;
        this.ParentForm = parent;

        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.ShowInTaskbar = false;
        this.Width = ParentForm.Width;
        this.Height = ParentForm.Height;
        this.Top = ParentForm.Top;
        this.Left = ParentForm.Left;
        this.StartPosition = ParentForm.StartPosition;
        // Set the opacity to 75%.
        this.Opacity = .75;
    }

    private void OverlayForm_Load(object sender, EventArgs e)
    {
        child.Show();
        child.TopMost = true;
        child.Focus();
        child.BringToFront();
    }
}
2。覆盖格式

1. Create an instance of the Child form 
2. Create an Instance of the Overlayform, Pass the objects Instances of Child and Parent(current form) as a parameter to the Constructor
3. Then Show the OverLay Form by using  ShowDialog Method.

Code:

public partial class ParentForm : Form
{
    public ParentForm()
    {

        InitializeComponent();
    }

    private void ParentForm_Load(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        ChildForm child1 = new ChildForm();
        // Create a new form.
        OverlayForm form2 = new OverlayForm(this, child1);
        child1.OverLay = form2;
        // Display the form as a modal dialog box.
        form2.ShowDialog(this);
    }
}
1. In the constructor store the childForm and ParentForm object in a local variables. 
       And Set the The properties (like width,height) to the Overlay Window
    2. In the OverlayForm_Load show the ChildForm window.

public partial class OverlayForm : Form
{
    public Form ParentForm { get; set; }
    public Form child { get; set; }
    public OverlayForm(Form parent, Form child)
    {
        InitializeComponent();
        this.child = child;
        this.ParentForm = parent;

        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.ShowInTaskbar = false;
        this.Width = ParentForm.Width;
        this.Height = ParentForm.Height;
        this.Top = ParentForm.Top;
        this.Left = ParentForm.Left;
        this.StartPosition = ParentForm.StartPosition;
        // Set the opacity to 75%.
        this.Opacity = .75;
    }

    private void OverlayForm_Load(object sender, EventArgs e)
    {
        child.Show();
        child.TopMost = true;
        child.Focus();
        child.BringToFront();
    }
}
这将给父窗体一个模糊的外观。我们还应该编写一些代码来关闭子窗体中的覆盖

3。子表单

1. Set the object of the Overlay  to a property in Child Window
2. And in the Form_Closing event of the child window, close the Overlay window.

public partial class ChildForm : Form
{
    //This is set in the Parent form where the child form instatce is created
    public Form OverLay { get; set; }
    public ChildForm()
    {
        InitializeComponent();
    }

    private void ChildForm_Load(object sender, EventArgs e)
    {
    }

    private void ChildForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        this.OverLay.Close();
    }
}
这对我来说很好。
但在打开child fucus后,应该在child form first(子窗体第一个)按钮上。我找到了最优雅的解决方案,它甚至有动画(尽管我出于自己的目的删除了该部分)。作者是“TommyCarlier”,定义如下:

class FadingOverlayForm : Form
    {
        readonly double fFinalOpacity;

        public FadingOverlayForm(Form owner, double finalOpacity)
        {
            StartPosition = FormStartPosition.Manual;
            FormBorderStyle = FormBorderStyle.None;
            ShowInTaskbar = false;
            Owner = owner;
            BackColor = Color.FromArgb(235, 245, 255); // or pick your own color
            fFinalOpacity = finalOpacity;
            if (fFinalOpacity < 0.01) fFinalOpacity = 0.01;
            else if (fFinalOpacity > 1.0) fFinalOpacity = 1.0;
        }

        public void FadeIn(TimeSpan duration)
        {
            Opacity = 0.01;
            Rectangle lWorkingArea = CalculateTotalScreenBounds();
            Bounds = new Rectangle(lWorkingArea.X - 150, lWorkingArea.Y - 150, 100, 100);
            Show();
            Bounds = new Rectangle(Owner.PointToScreen(Point.Empty), Owner.ClientSize);
            Animator.Animate(this, "Opacity", 0.01, fFinalOpacity, duration);
        }

        public void FadeOut(TimeSpan duration)
        {
            Animator.Animate(this, "Opacity", Opacity, 0, duration, EndFadeOut);
        }

        void EndFadeOut()
        {
            Form lOwner = Owner;
            Dispose();
            if (lOwner != null && !lOwner.IsDisposed)
                ActivateFirstOwnedForm(lOwner);
        }

        static void ActivateFirstOwnedForm(Form form)
        {
            foreach(Form lOwnedForm in form.OwnedForms)
                if (!lOwnedForm.IsDisposed)
                {
                    ActivateFirstOwnedForm(lOwnedForm);
                    return;
                }
            form.Activate();
        }

        static Rectangle CalculateTotalScreenBounds()
        {
            Rectangle lBounds = Rectangle.Empty;
            foreach(Screen lScreen in Screen.AllScreens)
                lBounds = Rectangle.Union(lBounds, lScreen.Bounds);
            return lBounds;
        }
    }

但是表单可以显示为MDI child,也可以显示为对话框,这将实现子窗口的目的。科林,看来你是对的。然而,我试图做谷歌还没有得到任何答案。相信你是对的。我想记下你的答案。