2

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

enter image description here

Community
  • 1
  • 1
Rocky
  • 405
  • 7
  • 17
  • Now that's tricky. Creating rounded corners controls in winforms is not that hard, but combining them with a semi-transparent form is hard. I probably solved this the wrong way, but by the time I was getting to it so much code have been written that I couldn't change it. The correct way is probably to start with [Hans Passant](http://stackoverflow.com/users/17034/hans-passant)'s trick as written in [this answer](http://stackoverflow.com/a/10267279/3094533) to create the semi-transparent background, and then figure out a way to stop the transparency key from showing around the corners. – Zohar Peled Apr 26 '16 at 05:33
  • I currently don't have the time to write a proper answer, Perhaps someone else might help, though. Where is Hans when you need him? – Zohar Peled Apr 26 '16 at 05:34
  • Waiting for your reply.... – Rocky Apr 26 '16 at 13:19
  • Try to remove the `Base.OnPaintBackground()` call in your panel. if that doesn't work, let me know and I'll post my solution (that might take a few days, though) – Zohar Peled Apr 26 '16 at 15:23
  • I tried it and it did not work. As of now I will provide with current solution itself until you provide a new one. – Rocky Apr 27 '16 at 04:46

1 Answers1

3

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();
Rocky
  • 405
  • 7
  • 17