I am currently working on a project where my requirement is to create a form which has rounded corners and also the rounded corners must be black . I have successfully created a form with rounded corners and another form with black border but When I mix the codes of both forms together , the code did not work as expected as the black border did not come properly on edges of the form . I know nothing about gdi+ in c# , So I request all respected community members to please help me correcting my code .
public partial class roundborderlessform : no_border_form
{
[System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern System.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
);
[System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
private static extern bool DeleteObject(System.IntPtr hObject);
protected override void OnPaint(PaintEventArgs e)
{
System.IntPtr ptr = CreateRoundRectRgn(0, 0, this.Width, this.Height, 50, 50); // _BoarderRaduis can be adjusted to your needs, try 15 to start.
this.Region = System.Drawing.Region.FromHrgn(ptr);
DeleteObject(ptr);
ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
}