仅使用钢笔工具在C#中画圆,而不使用椭圆方法

仅使用钢笔工具在C#中画圆,而不使用椭圆方法,c#,graphics,C#,Graphics,我所做的代码是硬编码的,我想把它转换成圆圈,我可以添加任何片段或其他东西 代码是用C语言编写的,输出像是一个矩形,我必须把它转换成一个圆 private void pictureBox1_Click(object sender, EventArgs e) { int length = 100; int flag = 0; int flag2 = 0; int flag3 = 0; P

我所做的代码是硬编码的,我想把它转换成圆圈,我可以添加任何片段或其他东西

代码是用C语言编写的,输出像是一个矩形,我必须把它转换成一个圆

        private void pictureBox1_Click(object sender, EventArgs e)
        {
        int length = 100;
        int flag = 0;
        int flag2 = 0;
        int flag3 = 0;

        Pen p = new Pen(Color.Red, 4);
        Graphics g = pictureBox1.CreateGraphics();
        Brush redBrush = new SolidBrush(Color.Red);
        for (int i = 0; i < 20; i++)
        {
                if(i==0 || i<10)
                {
                    g.DrawLine(p, 622 - 10 * i, 229+10*i, 623 - 10 * i, 229+10*i);
                }
                if(i==10)
                {
                    flag = 1;
                }
                if(flag==1)
                {
                    g.DrawLine(p, 622 - 10 * i, 419 - 10 * i, 623 - 10 * i, 419-10*i);
                    flag2 = 1;
                }
                if(flag2 == 1)
                {
                    g.DrawLine(p, 622 - 10 * i, 29+10*i, 623 - 10 * i, 29+10*i);
                    flag3 = 1;
                }
                if (flag3 == 1)
                {
                    g.DrawLine(p, 432 + 10 * i, 29+10*i, 433 + 10 * i, 29 + 10 *i);
                }

        }
private void pictureBox1\u单击(对象发送方,事件参数e)
{
整数长度=100;
int标志=0;
int flag2=0;
int flag3=0;
钢笔p=新钢笔(颜色为红色,4);
Graphics g=pictureBox1.CreateGraphics();
画笔红色画笔=新的SolidBrush(颜色为红色);
对于(int i=0;i<20;i++)
{

如果(i==0 | | i有用于此的内置函数,请改用g.drawerlipse()。

您可以这样做

void DrawCircle(Graphics g, Pen p, Point centre, double radius=20, int sides = 360)
{
    var angle = 2 * Math.PI / sides;
    for (int i = 0; i < sides; i++)
    {
        Point from = new Point((int)(radius * Math.Sin(i * angle) + centre.X), (int)(radius * Math.Cos(i * angle) + centre.Y));
        Point to = new Point((int)(radius * Math.Sin((i+1) * angle) + centre.X), (int)(radius * Math.Cos((i+1) * angle) + centre.Y));
        g.DrawLine(p, from, to);
    }
}
增加边数以使其更精确

或者

g.DrawEllipse(p, (float)(centre.X-radius), (float)(centre.Y-radius), (float)radius*2, (float)radius*2);

你为什么不能用椭圆法?我特别说过我不应该用椭圆法
g.DrawEllipse(p, (float)(centre.X-radius), (float)(centre.Y-radius), (float)radius*2, (float)radius*2);