0

I have found code :

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 Arc
        GraphPath.AddArc(Rect.X + w2, Rect.Y + w2, radius, radius, 180, 90);

        //Top-Right Arc
        GraphPath.AddArc(Rect.X + Rect.Width - radius - w2, Rect.Y + w2, radius, radius, 270, 90);

        //Bottom-Right Arc
        GraphPath.AddArc(Rect.X + Rect.Width - w2 - radius,
                           Rect.Y + Rect.Height - w2 - radius, radius, radius, 0, 90);
        //Bottom-Left Arc
        GraphPath.AddArc(Rect.X + w2, Rect.Y - w2 + Rect.Height - radius, radius, radius, 90, 90);

        //Close line ( Left)           
        GraphPath.AddLine(Rect.X + w2, Rect.Y + Rect.Height - r2 - w2, Rect.X + w2,Rect.Y + r2 + w2);
                   
        //GraphPath.CloseFigure();            
        
        return GraphPath;
    }

Can someone explain me how i suppose to change it to make button only one sided rounded?

Prasad Telkikar
  • 15,207
  • 5
  • 21
  • 44
Helpmepls
  • 9
  • 3
  • 1
    Can you show us a sample output button that you want? – tontonsevilla Aug 27 '20 at 08:55
  • which side do you want rounded? – Pac0 Aug 27 '20 at 09:01
  • Here's what I get from this kind of "question": I've found a code that does what I need. I don't understand the code I've found. Please change it for me to do what I want. Sorry, SO is not a free code-writing service. We're here to help fellow developers solve problems. You don't have a problem, you have a job you want done for free (granted, a very small job, but a job none the less). – Zohar Peled Aug 27 '20 at 09:13
  • https://ibb.co/wr2H01h i need to create button like this one. – Helpmepls Aug 27 '20 at 09:15
  • I just need an explanation , how to leave normal corners if you are using addarc function. – Helpmepls Aug 27 '20 at 09:17
  • @ZoharPeled It's my school assignment , im having a trouble by creating it by my own, so i used forums so someone could explain me or show me how to leave normal corners. Is it that big issue? – Helpmepls Aug 27 '20 at 09:22
  • @Pac0 Bottom right – Helpmepls Aug 27 '20 at 09:31
  • @Helpmepls for you, no, it's not a big deal. For us, that reads these "give me codez" questions all the time, it gets kinda annoying every now and then, so forgive me if I'm not inclined to change that code for you. Also, please note that you probably wont learn anything from blindingly copying code from online resources and having other people modify it for you because you don't understand it. – Zohar Peled Aug 27 '20 at 09:36
  • @ZoharPeled That's why im asking for explanation :) – Helpmepls Aug 27 '20 at 09:39
  • "Bottom right " is not a side, that's a corner. You want only one corner rounded? What you can try is to comment every "AddArc" but one, to see the effect of each part of the code. Then you may need to draw what's missing when you keep only the round part you want. – Pac0 Aug 27 '20 at 09:50
  • Oh, sorry, didn't see that part. I apologize. Basically, you should leave only one `AddArc` in the corner you want to be rounded (bottom right, is that the one?) and use `AddLine` instead of the others . – Zohar Peled Aug 27 '20 at 09:51
  • [This](https://stackoverflow.com/questions/28486521/rounded-edges-in-button-c-sharp-winforms/28486964#28486964) is a similar solution but with the lines added for clarity. The AddXXX calls will add connecting lines automatically, so it is a bit harder to see the whole picture.. – TaW Aug 27 '20 at 09:58
  • @TaW by AddXXX you mean AddLine? Im not quite sure how the parameters work. Is there simple solution how to draw a line till the end (till the corner) or i need to calculate everything up? – Helpmepls Aug 27 '20 at 10:18
  • I meant that any DrawXXX command will connect to the last one, unless told to not do that. - As for 'calculating' the corners: That is hardly a cacluation, is it? You can simply take the two corners of the button ClientRectangle – TaW Aug 27 '20 at 10:21

1 Answers1

0

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;

Helpmepls
  • 9
  • 3