C# child form over main form having greyed out effect

我的梦境 提交于 2019-12-12 16:53:39

问题


I want a child form to be displayed over main form with all the empty spaces around having some opacity. I achieved the same using the solution provided in C# winforms pop up with background faded.

Now I want the panel that is used in the child form to have rounded corner. Any help?

I used the panel from below link to have rounded corners. The panel is having rounded corner but still the rectangle line(highlighted in image) is visible. Is there any way to make it disappear ? http://www.openwinforms.com/creating_cool_gradient_panel_gdi.html


回答1:


I found the solution.

On form paint add:

 this.BackColor = Color.Lime;
        this.TransparencyKey = Color.Lime;

        var hb = new HatchBrush(HatchStyle.Percent60, this.TransparencyKey);
        e.Graphics.FillRectangle(hb, this.DisplayRectangle);

On form load make the panel edge round where ctrl = panel.

Rectangle bounds = new Rectangle(0, 0, ctrl.Width, ctrl.Height);
        int iCornerRadius = 20;
        GraphicsPath gpath = new GraphicsPath();
        gpath.AddArc(bounds.X, bounds.Y, iCornerRadius, iCornerRadius, 180, 90);
        gpath.AddArc(bounds.X + bounds.Width - iCornerRadius, bounds.Y, iCornerRadius, iCornerRadius, 270, 90);
        gpath.AddArc(bounds.X + bounds.Width - iCornerRadius, bounds.Y + bounds.Height - iCornerRadius, iCornerRadius, iCornerRadius, 0, 90);
        gpath.AddArc(bounds.X, bounds.Y + bounds.Height - iCornerRadius, iCornerRadius, iCornerRadius, 90, 90);
        gpath.CloseAllFigures();

        ctrl.Region = new Region(gpath);
        ctrl.Show();


来源:https://stackoverflow.com/questions/36855559/c-sharp-child-form-over-main-form-having-greyed-out-effect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!