How to make a Non Rectangular Winform?
Asked Answered
V

1

4

I am using the code below to change to shape of the winform.

It's changing the shape, but not like how I wanted. I need the form to have curved corners.

What points should I use to get it?

public void MakeNonRectangularForm()
{
    var p = new GraphicsPath();

    int width  = ClientSize.Width;
    int height = ClientSize.Height;

    p.AddClosedCurve(new Point[] { new Point(width / 2, height / 2), 
       new Point(width, 0), new Point(width, height / 3),
       new Point(width - width / 3, height),
       new Point(width / 7, height - height / 8)});

    Region = new Region(p);
}
Vansickle answered 19/4, 2010 at 1:31 Comment(1)
In that past many mp3 players like Winamp or Windows Media Player had some special themes with freeform Windows that's drawn with an image, like an oval or a leaf-like form. The curves are smoothed by the alpha channel. You'll see the jaggy artifacts if you change from 32-bit to 24-bit colorZobias
L
3

The following is some code I have used to create rounded edges before, using AddArc and lines to piece together the border:

(You can play with xRadius and yRadius to achieve your desired amount of "rounded-ness")

int xRadius = {insert value here};
int yRadius = {insert value here};

GraphicsPath edge = new GraphicsPath();

int rightHandLeft = this.Width - xRadius - 1;
int bottomSideTop = this.Height - yRadius - 1;

edge.AddArc(0, 0, xRadius, yRadius, 180, 90);
edge.AddLine(xRadius, 0, rightHandLeft, 0);

edge.AddArc(rightHandLeft, 0, xRadius, yRadius, 270, 90);
edge.AddLine(this.Width, yRadius, this.Width, bottomSideTop);

edge.AddArc(rightHandLeft, bottomSideTop, xRadius, yRadius, 0, 90);
edge.AddLine(rightHandLeft, this.Height, xRadius, this.Height);

edge.AddArc(0, bottomSideTop, xRadius, yRadius, 90, 90);
edge.AddLine(0, bottomSideTop, 0, yRadius);

this.Region = new Region(edge);
Ligulate answered 19/4, 2010 at 1:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.