我在尝试将圆圈变成同心模式时遇到了麻烦。例如,下一个圆圈越大,然后越大,等等。有点像地球的核心,内核,外核和地壳。
以下是我的所有代码:
namespace ClickAppearBalls
{
public partial class Form1 : Form
{
private Random randClick;
private Graphics paper;
private Pen pen;
public Form1()
{
InitializeComponent();
randClick = new Random();
paper = picCanvas.CreateGraphics();
}
private void picCanvas_Click(object sender, EventArgs e)
{
int x, y, size1, size2;
x = picCanvas.Height / 2;
y = picCanvas.Width / 2;
Color color = Color.FromArgb(randClick.Next(0, 256), randClick.Next(0, 256), randClick.Next(0, 256));
Pen pen = new Pen(color);
pen.Width = 3;
size1 = 30;
size2 = 30;
paper.DrawEllipse(pen, x, y, size1, size2);
}
}
}
答案 0 :(得分:0)
您需要在类上定义size变量,以便可以在连续单击时使用它。然后你需要每次点击都增加它。
namespace ClickAppearBalls
{
public partial class Form1 : Form
{
private Random randClick;
private Graphics paper;
private Pen pen;
private int circleSize = 30;
public Form1()
{
InitializeComponent();
randClick = new Random();
paper = picCanvas.CreateGraphics();
}
private void picCanvas_Click(object sender, EventArgs e)
{
int x, y;
x = picCanvas.Height / 2;
y = picCanvas.Width / 2;
Color color = Color.FromArgb(randClick.Next(0, 256), randClick.Next(0, 256), randClick.Next(0, 256));
Pen pen = new Pen(color);
pen.Width = 3;
paper.DrawEllipse(pen, x - circleSize/2, y - circleSize/2, circleSize, circleSize);
circleSize += 10; // increase size here
}
}
}