Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here is what i got, it makes whole button rounded. I know that i suppose to change arcadd ones to addline, but the parameters gets me super confused. I can't understand how to draw normal corners and leave only for example bottom right corner rounded or bottom right and top right.

GraphicsPath GetRoundPath(RectangleF Rect, int radius, float width=0)
       {
           //Fix radius to rect size
           radius = (int) Math.Max(( Math.Min(radius, Math.Min(Rect.Width, Rect.Height)) - width),1);
           float r2 = radius / 2f;
           float w2 = width / 2f;
           GraphicsPath GraphPath = new GraphicsPath();
           //Top-Left
          GraphPath.AddArc(Rect.X + w2, Rect.Y + w2, radius, radius, 180, 90);
           //Top-Right
           GraphPath.AddArc(Rect.X + Rect.Width - radius - w2, Rect.Y + w2, radius, radius, 270, 90);
           //Bottom-Right
           GraphPath.AddArc(Rect.X + Rect.Width - w2 - radius,
                              Rect.Y + Rect.Height - w2 - radius, radius, radius, 0, 90);
           //Bottom-Left
           GraphPath.AddArc(Rect.X + w2, Rect.Y - w2 + Rect.Height - radius, radius, radius, 90, 90);
           //Close line
           GraphPath.AddLine(Rect.X + w2, Rect.Y + Rect.Height - r2 - w2, Rect.X + w2, Rect.Y + r2 + w2);

           //GraphPath.CloseFigure();
           return GraphPath;
       }


What I have tried:

If you willing me to help me, please at least explain what i suppose to write in parameters or show me i know that wont help me much to learn, but then at least i can study more easily it. Sorry for dumb question, im trying to do this for a week now for my school assignment. 
Posted
Updated 30-Aug-20 21:10pm

I see you have picked code from here: Button with Rounded Edges C#[^]

Looking at the code, there are clear segregation for each corner (4 corners of a button) and how to handle it. If you are struggling in removing (not using) code for any specific corner then first you need to understand the code and then copy to use it.

All the details are there, if you just try with the sample itself (you would need a small tweak), you can get one or few (instead of all) corners rounded.
 
Share this answer
 
v2
Comments
BillWoodruff 31-Aug-20 1:14am    
+5 Good catch
IF you get code from an article - on Codeproject or elsewhere - the first thing to do is to ask the author: Button with Rounded Edges C#[^]
If you look, you will see a forum at the bottom where you can talk directly to the person that wrote the article and he can respond.

But ... if you don't understand how to modify fairly simple code then you are punching way above your weight - you need to understand how it works before you use it. You are not going to be able to get through your whole course or your career just finding the right code on the internet and shoving it in your app unchanged, you will have to write your own code, and modify others. And that means you need to understand code before you use it - which is a damn good idea anyway, since if you don't, you have no idea what else it does!
 
Share this answer
 
After some studying i managed to make it for future users.
Here is code for only bottom right corner rounded:
radius = (int)Math.Max((Math.Min(radius, Math.Min(Rect.Width, Rect.Height)) - width), 1);
           float r2 = radius / 2f;
           float w2 = width / 2f;
           GraphicsPath GraphPath = new GraphicsPath();



           GraphPath.AddLine(Rect.X + w2, Rect.Y + w2, Rect.X, Rect.Y);
           GraphPath.AddLine(Rect.X + Rect.Width, Rect.Y, Rect.X + Rect.Width - w2, Rect.Y);
           GraphPath.AddArc(Rect.X + Rect.Width - w2 - radius,
                              Rect.Y + Rect.Height - w2 - radius, radius, radius, 0, 90);
           GraphPath.AddLine(Rect.X + w2, Rect.Y - w2 + Rect.Height, Rect.X - w2, radius);

           GraphPath.AddLine(Rect.X + w2, Rect.Y + Rect.Height + r2 + w2 + Rect.Y, Rect.X + w2, Rect.Y + Rect.Y);

           return GraphPath;


Top Left

GraphPath.AddLine(Rect.X + w2, Rect.Y + w2, Rect.X, Rect.Y);
GraphPath.AddArc(Rect.X + Rect.Width - radius - w2, Rect.Y + w2, radius, radius, 270, 90);
GraphPath.AddLine(Rect.X + Rect.Width-w2 ,Rect.Y + Rect.Height, Rect.X+Rect.Width,Rect.Y+Rect.Height-w2);
GraphPath.AddLine(Rect.X + w2, Rect.Y - w2 + Rect.Height, Rect.X - w2, radius);
GraphPath.AddLine(Rect.X + w2, Rect.Y + Rect.Height + r2 + w2 + Rect.Y, Rect.X + w2, Rect.Y + Rect.Y);  
return GraphPath;

Top Right

GraphPath.AddArc(Rect.X + w2, Rect.Y + w2, radius, radius, 180, 90);
GraphPath.AddLine(Rect.X + Rect.Width, Rect.Y, Rect.X + Rect.Width - w2, Rect.Y);
GraphPath.AddLine(Rect.X + Rect.Width - w2, Rect.Y + Rect.Height, Rect.X + Rect.Width, Rect.Y + Rect.Height - w2);
GraphPath.AddLine(Rect.X + w2, Rect.Y - w2 + Rect.Height, Rect.X - w2, radius);
GraphPath.AddLine(Rect.X + w2, Rect.Y + Rect.Height - r2 - w2, Rect.X + w2, Rect.Y + r2 + w2);
return GraphPath;
 
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