开发者

C# Best Method to Dim Screen, Multiple Windows Forms?

开发者 https://www.devze.com 2023-04-03 19:36 出处:网络
So I\'ve written code to create a new Windows form from the parent that is fullscreen, black and opacity of 80% to create a dimming effect.

So I've written code to create a new Windows form from the parent that is fullscreen, black and opacity of 80% to create a dimming effect.

Then another form is shown above this to show progress.

The code is currently looking like this:

    this.Enabled = false;

    frmDimScreen.BackColor = Color.Black;
    frmDimScreen.Opacity = .8;
    frmDimScreen.FormBorderStyle = FormBorderStyle.None;
    frmDimScreen.Size = new Size(splitContainerMain.Width - 4, splitContainerMa开发者_Python百科in.Height - 2);
    frmDimScreen.StartPosition = FormStartPosition.Manual;
    frmDimScreen.ShowIcon = false;
    frmDimScreen.ShowInTaskbar = false;
    frmDimScreen.Show();
    frmDimScreen.Location = new Point(splitContainerMain.Location.X + 2,         ((splitContainerMain.Location.Y + tsMainTools.Height) - 4));

    addImgIL.ShowIcon = false;
    addImgIL.ShowInTaskbar = false;
    addImgIL.TopMost = true;
    addImgIL.Show();
    addImgIL.Location = new Point((this.Width - addImgIL.Width) / 2, (this.Height -         addImgIL.Height) / 2);
    addImgIL.BringToFront();

Obvioulsy the main reason I'm questioning this is if the parent window loses focus, then the child forms get out of order and are not layered correctly. I know I can handle this via OnPaint, but looking for the best solution.

The question/problem, is this the best method to achieve what I am attempting? Should I be using forms or graphics to create the dimming? What's everyones experience with this?

Thanks in advance!


Another approach using only a single window would be to use an alpha blended image to draw the transparent dark background (you could even have a gradient) with a non-transparent custom drawn progress bar. See http://www.codeproject.com/KB/GDI-plus/perpxalpha_sharp.aspx .

In that project you can find a class that you can use to easily assign an alpha blended Bitmap to a form's background. The problem with this method is that you must custom draw everything on the form, including the progress bar or whatever other controls you need on it.

The effect that you are trying to achieve is kind of unusual for a windows application, that is why the best method is not very straightforward.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号