下面是我在c#中的picturebox代码。我无法找到一种方法来检查点击坐标(x,y)是否被更改,如果它们被更改,则circleize的值应更改为20.
杂项:该程序适用于同心圆。 circlesize 20表示圆圈应该从小尺寸开始再次绘制。
private void picCanvas_Click_1(object sender, EventArgs e)
{
int x, y;
if (comboBox1.SelectedItem == "Draw")
{
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, x1 - circleSize / 2, y1 - circleSize / 2, circleSize, circleSize);
circleSize += 10; // increase size here
count += 1;
MouseEventArgs me = (MouseEventArgs)e;
Point coordinates = me.Location;
x = me.X;
y = me.Y;
}
if (comboBox1.SelectedItem == "Change Location")
{
MouseEventArgs me = (MouseEventArgs)e;
Point coordinates = me.Location;
x = me.X;
y = me.Y;
for (; i <= 0; i++)
{
for (int j = 0; j < count; j++)
{
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
a = 15;
}
}
if (a == 15)
{
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
}
}
}
答案 0 :(得分:0)
您可以在picCanvas_Click_1
函数范围之外定义两个变量,例如prevX
和prevY
。
然后在退出picCanvas_Click_1
之前(例如在最后一行)将它们设置为
prevX = x;
prevY = y;
然后在picCanvas_Click_1
中检查它们是否已更改,并执行您想要的操作
if (prevX != x || prevY != y)
{
//do what you want
}