Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to create a small Winform with some round edges (all 4 corners).

I got some code from the internet

But, the above code is not working as expected. This code only round the top upper corners and the right upper corner is not so perfectly rounded (have some pixel effect). The bottoms are not able to round either.
As I try to maximize the window is not able to maximize with its full length (working without this round edge code).

I have searched for the solution over the internet but didn't any other method or solution for this issue.

What I have tried:

C#
[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
        );

            if (isCustomTitle)
            {
                this.FormBorderStyle = FormBorderStyle.None;
                Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
            }
Posted
Updated 3-Jun-21 22:23pm
Comments
Ralf Meier 4-Jun-21 3:37am    
it will be helpful to see the code from the method "CreateRoundRectRgn" - perhaps you improve your question (use the widget "improve question") and provide this missing code ...

If you got code from the internet, then go back there and ask them: they know their code better than we will!
 
Share this answer
 
Comments
thrainder 4-Jun-21 5:26am    
It's a generic method, not a secrete custom code so that only the creator knows about it. If you know how can I improve this then share your thoughts else if you don't know how it works then please leave it as it is. if you google "round edge in winforms" then surely, about top 10 sites will be using the same method. Even on CodeProejct.
CreateRoundRect isn't pixel perfect so as far as I know you won't be able to get smooth corners using only that function.

An example of smooth corners can be found for example here c# - Creating Smooth Rounded Corners in WinForm Applications [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900