检查图片框中的坐标是否更改,然后单击并返回一个值
本文关键字:返回 单击 一个 然后 坐标 是否 检查 | 更新日期: 2023-09-27 18:35:31
下面是我在 c# 中用于图片框的代码。我想不出一种方法来检查单击坐标(x,y)是否更改,如果更改,则circlesize的值应更改为20。
杂项:该程序适用于同心圆。 圆大小 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
}
}
}
您可以在picCanvas_Click_1
函数的作用域之外定义两个变量,例如prevX
和prevY
。
然后在退出picCanvas_Click_1
之前(例如在最后一行)将它们设置为这样
prevX = x;
prevY = y;
然后检查它们是否在picCanvas_Click_1
中更改,然后像这样做你想做的事
if (prevX != x || prevY != y)
{
//do what you want
}