Share via

Rounded form Corners

AMER SAID 396 Reputation points
2022-12-08T17:41:11.82+00:00

hi

Use this code to round the edge corners of the form.
The code works, but when increasing the size of the form or decreasing the size of the form, problems occur with the 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, // width of ellipse  
            int nHeightEllipse // height of ellipse  
        );  
  
        public Form1()  
        {  
            InitializeComponent();  
            this.FormBorderStyle = FormBorderStyle.None;  
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));  
        }  
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2022-12-08T17:52:13.857+00:00

Try this:

public Form1( )  
{  
    InitializeComponent( );  
  
    this.FormBorderStyle = FormBorderStyle.None;  
  
    Resize += ( s, a ) =>  
    {  
        Region = System.Drawing.Region.FromHrgn( CreateRoundRectRgn( 0, 0, Width, Height, 20, 20 ) );  
    };  
}  

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.