I am trying to have a User Control that has rounded corners. It doesnt have a fixed size but it usually doesnt have a width much more than 120 pixels.
I need the User Control and its contents(a label and a table) to have rounded edges and look like a round box.
I have used this code.
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
public static System.Drawing.Region GetRoundedRegion(int controlWidth, int controlHeight)
{
return System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, controlWidth - 5, controlHeight - 5, 20, 20));
}
This gives the control rounded corners but after it has been running afew times and i have added multiples of my User Control to the form it will cause a leak and i will get the whitebox with a red cross on my user controls.
Is there a better way of doing this?