Hello, All. I hate doing this but I’ve fiddled with it for some time with no luck. It’s been 57 years since my last geometry class, and I’m stumped.
I am trying to create a GraphicsPath that is very similar to what I would get if I used AddRoundRectangle and added it to the margins of my DesktopContainer. Think of the border around a DesktopButton. In paint I will be selecting one of 3 versions.
All three versions will have a horizontal line, to width (or arc), top and bottom.
One additional note - I discovered after my post that the first ‘AddLineToPoint’ on line 10 is not needed because of the way GraphicPath works. The first AddArc call on line 11 adds the line from the initial point to the arc.
I am so sorry. When I try to change it to be rounded on the left side, I can’t seem to get the StartRadian and EndRadian to do anything but draw pretty much a whole circle with a line through it. I just don’t understand Radians.
It may help you to not use the constant names (except Pi), and think about the area that you are writing with the top left at 0,0 instead bottom left 0,0 as we learned in school.
Then you write your code with specific numbers to understand what happens when you add a line or add an arc. This may help you understand how things work.
Here’s a reference for the startRadian and endRadian:
In my example the first arc starts at the top of the circle, so 1.5 * Pi and ends on the right side, so 0. The second arc starts on the right side, so 0 and ends on the bottom, so 0.5 * Pi.
The diagram made all the difference. Here’s the code for the left curve. Note that the final argument, counterClockWise, has to be changed to True.
I also just used the Width and Height of the DesktopContainer rather than making them constants.
#pragma unused areas
Const Pi = 3.14159
Const x = 0
Const y = 0
Const arcRadius = 10
// Left Rounded
Var gPath As New GraphicsPath
gPath.MoveToPoint(x+Width, y)
gPath.AddLineToPoint(x+arcRadius, y)
gPath.AddArc(x+arcRadius, y+arcRadius, arcRadius, 1.5Pi, Pi, True)
gPath.AddArc(x+arcRadius, y+Height-arcRadius, arcRadius, Pi, 0.5Pi, True)
gPath.AddLineToPoint(x + Width, y+Height)
g.DrawPath(gPath)