检查图片框中的坐标是否更改单击并返回一个值

时间:2014-12-28 09:28:12

标签: c# .net winforms coordinates

下面是我在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
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您可以在picCanvas_Click_1函数范围之外定义两个变量,例如prevXprevY

然后在退出picCanvas_Click_1之前(例如在最后一行)将它们设置为

prevX = x;
prevY = y;

然后在picCanvas_Click_1中检查它们是否已更改,并执行您想要的操作

if (prevX != x || prevY != y)
{
  //do what you want
}