在C#中连续创建圆

Creating Circles in a row in C#
2021-09-14
  •  译文(汉语)
  •  原文(英语)

我对编程非常陌生,对于我正在学习的实际练习有一个快速的问题.我正在尝试创建一个应用程序,用户可以在其中输入行数和列数,在其中行将彼此相邻绘制(本质上构成一个圆网格)

我已经可以在C#中使用矩形对象,并将其X轴值移动一定量,但我无法找到如何使用圆来完成此操作.这是否以相同的方式工作?我在MSDN上看到有一个圈子课程,但是我无法使它工作.我需要用椭圆填充做一些事情吗?因为这是目前我可以弄清楚如何绘制圆的唯一方法.

我不是在寻找一个完整的解决方案,而只是寻找一些基本的指导来帮助新手学习.

谢谢!!

解决过程1

假设您有桌面winforms应用程序,并使用System.Drawing.Graphics对象在窗口内绘制.

要绘制矩形,您可能使用了DrawRectangle方法之一:

// Create bounding rectangle.
Rectangle rect = new Rectangle(0, 0, 200, 200);

// Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, rect);

要绘制圆形而不是矩形,只需使用DrawEllipse方法,并通过移动x和y坐标,以与您相同的方式移动边界矩形.

// Create bounding rectangle.
Rectangle rect = new Rectangle(0, 0, 200, 200);

// Draw circle to screen.
e.Graphics.DrawEllipse(blackPen, rect);

I am very new to programming and have a quick question regarding a practical exercise i am undergoing for my studies. I am trying to create an application where the user can enter the number of rows and the nuber of columns in which circles will be drawn next to each other (to make a grid of circles essentially)

I have been able to do this in C# by using a rectangle object and shifting it's X axis value over by an amount but i cannot find out how to do this with a circle. Does this work in the same way? I have seen on MSDN that there is a circle class but i can't get this to work. Do i need to do some thing with a fill ellipse? As this is the only way i can currently figure out how to draw a circle.

I am not looking for a complete solve, just a few basic pointers to help a newbie leearn the ropes.

Thanks!!

Solutions1

Assuming that you have desktop winforms application, and using System.Drawing.Graphics object to draw inside window.

To draw a rectangle, you probably use one of DrawRectangle methods:

// Create bounding rectangle.
Rectangle rect = new Rectangle(0, 0, 200, 200);

// Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, rect);

To draw a circle instead of rectangle, just use DrawEllipse method, and move bounding rectangle the same way you did, by shifting x and y coordinates.

// Create bounding rectangle.
Rectangle rect = new Rectangle(0, 0, 200, 200);

// Draw circle to screen.
e.Graphics.DrawEllipse(blackPen, rect);
转载于:https://stackoverflow.com/questions/15594309/creating-circles-in-a-row-in-c-sharp

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入