0

ill attach a ss of both the smoothed version, then the ugly version. It appears any time i set the region to my rounded rectangle shape the back color of my form is being shown behind the path's pixels making the smooth look turn ugly. How can I do this better?

Attempting to make a rounded form thats smoothed!

Smooth Path

Smoothness disrupted by form after setting forms region to path

The code im using to draw the rectangle

        SolidBrush sb = new SolidBrush(Color.Black);
        Size s = new Size(10, 10);
        Rectangle r = new Rectangle(new Point(0, 0), s);
        r.Width = this.Width;
        r.Height = this.Height;

        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

        SetNewRegion.FillRoundedRectangle(e.Graphics, sb, r, 25);

the SetNewRegion file function.

    public static void FillRoundedRectangle(this Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius)
    {
        if (graphics == null)
            throw new ArgumentNullException("graphics");
        if (brush == null)
            throw new ArgumentNullException("brush");

        using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
        {
            graphics.FillPath(brush, path);
            
        }
    }

    public static GraphicsPath RoundedRect(Rectangle bounds, int radius)
    {
            int diameter = radius * 2;
            Size size = new Size(diameter, diameter);
            Rectangle arc = new Rectangle(bounds.Location, size);
            GraphicsPath path = new GraphicsPath();

            if (radius == 0)
            {
                path.AddRectangle(bounds);
                return path;
            }

            path.AddArc(arc, 180, 90);
            arc.X = bounds.Right - diameter;
            path.AddArc(arc, 270, 90);
            arc.Y = bounds.Bottom - diameter;
            path.AddArc(arc, 0, 90);
            arc.X = bounds.Left;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();
            return path;
    }

Then finally, simply adding the region by using an altered version of FillRoundedRectangle to enable me to build a region using the same path but in region form.

this.Region = SetNewRegion.WindowBounds(e.Graphics, sb, r, 25);
RedKabin
  • 31
  • 3
  • The `e.Graphics.SmoothingMode` is not to anti-alias a region. Why do you need to set the region here? Just handle the `Paint` event of a `Label` or a `Panel` and draw the rounded rectangle. – dr.null Nov 25 '20 at 06:36
  • Regions are all about pixels and cannot be smooth. – TaW Nov 25 '20 at 09:25
  • You can use a rounded Form like this one: [How can I draw a rounded rectangle as the border for a rounded Form?](https://stackoverflow.com/a/56533229/7444103) and modify the Region bounds as described here: [How to avoid visual artifacts of colored border of zoomable UserControl with rounded corners?](https://stackoverflow.com/a/54794097/7444103). You have to paint the Region content yourself. Note that, as described in the second link, the Region bounds are *shrinked* to leave a border outside the Region. There, you can paint a semi-transparent content. – Jimi Nov 25 '20 at 10:17

0 Answers0