Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is hard for me to actually explain so I created a mockup for what I want.

Mockuk example

Can someone here explain how I could make this? Maybe some code could help but I think a general idea or direction can be sufficient enough.

I want to darken the parent background whenever a new window is opened in front of it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
330 views
Welcome To Ask or Share your Answers For Others

1 Answer

Take a screenshot of the form and paint a semi-transparent rectangle over it. Add that image to a panel the size of the form and bring it to the front. Display your dialog. Get rid of the panel:

    private void button1_Click(object sender, EventArgs e)
    {
        // take a screenshot of the form and darken it:
        Bitmap bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
        using (Graphics G = Graphics.FromImage(bmp))
        {
            G.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
            G.CopyFromScreen(this.PointToScreen(new Point(0, 0)), new Point(0, 0), this.ClientRectangle.Size);
            double percent = 0.60;
            Color darken = Color.FromArgb((int)(255 * percent), Color.Black);
            using (Brush brsh = new SolidBrush(darken))
            {
                G.FillRectangle(brsh, this.ClientRectangle);
            }
        }

        // put the darkened screenshot into a Panel and bring it to the front:
        using (Panel p = new Panel())
        {
            p.Location = new Point(0, 0);
            p.Size = this.ClientRectangle.Size;
            p.BackgroundImage = bmp;
            this.Controls.Add(p);
            p.BringToFront();

            // display your dialog somehow:
            Form frm = new Form();
            frm.StartPosition = FormStartPosition.CenterParent;
            frm.ShowDialog(this);
        } // panel will be disposed and the form will "lighten" again...
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...