Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I draw an arc that goes from 0 degrees to 180, and his perimiter is 20mm?

The picture with an explanation[^]

What I have tried:

C#
Graphics g = Graphics.FromImage(bmp);
g.PageUnit = GraphicsUnit.Millimeter;
Rectangle r = new Rectangle(0, 0, (int)(Math.Round((40 / 25.4) / (float)Math.PI * g.DpiX) * 2), (int)(Math.Round((40 / 25.4) / (float)Math.PI * g.DpiY) * 2));
g.DrawArc(Pens.Black, r, 0, 180);

This is what I tried so far. I've came to this conclusion :

C#
g.DrawLine(Pens.Black, 1, 1, 1, (float)Math.Round((2 / 25.4) * g.DpiY));


This code draws a line that is 2mm long. But the first part of code which is supposed to be working good isn't working for some reason and its displaying a semiarc bigger than its supposed to be.
Posted
Updated 11-Dec-17 3:23am

1 solution

I would use the graphics DrawArc method and call this from overridden OnPaint(PaintEventArgs e)

private void MyDrawArc(PaintEventArgs e)
{
// Create pen.d
Pen pen = new Pen(Color.Black, 22);

// coordinates
int x = 100;
int y = 100;
int width = 200;
int height = 200;

// start and sweep angles
int startAngle = 0;
int sweepAngle = -180;

// Draw the arc to the screen.
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
e.Graphics.DrawArc(pen, x, y, width, height, startAngle, sweepAngle);
}
 
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