C#窗体中的灯箱样式模态对话框

时间:2011-07-04 08:54:45

标签: c# windows

我想在c#windows窗体中显示jquery灯箱样式模型对话框。我的对话框将出现在MDI子窗体按钮的Click事件中。我是怎么做到的?请帮帮我。

1 个答案:

答案 0 :(得分:0)

如果你的意思是掩盖父表单,那么没有简单的方法可以做到这一点,我所做的是在父表面上创建一个透明表单,然后打开另一个自定义表单作为对话框假面具窗口的顶部。

类似这样的地方,window是你的弹出窗口,而owner是要掩盖的形式:

Mask = new LayerWindow();
Mask.Show(owner);
window.Show(Mask);

这就是我用作面具的原因:

public class LayerWindow : Form
{
    public LayerWindow()
    {
        FormBorderStyle = FormBorderStyle.None;
        StartPosition = FormStartPosition.Manual;
        TransparencyKey = Color.Fuchsia;
        base.BackColor = Color.Black;
        Opacity = 0.50;
        ShowInTaskbar = false;
    }

    public void Show(Control parent)
    {
        if (parent == null)
            throw new ApplicationException("No parent provided");

        var container = parent.FindForm();
        if (container == null)
            throw new ApplicationException("No parent Form found. Make sure that the control is contained in a form before showing a popup.");

        Location = PointToScreen(container.Location);
        Bounds = container.Bounds;

        Owner = container;
        Owner.Enabled = false;

        base.Show(container);
    }

    public void Unmask()
    {
        if (Owner != null)
            Owner.Enabled = true;

        Hide();
    }