Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何实现在图片框或图像上绘制的多个或列表矩形的移动?_C#_Image Processing_C# 4.0 - Fatal编程技术网

C# 如何实现在图片框或图像上绘制的多个或列表矩形的移动?

C# 如何实现在图片框或图像上绘制的多个或列表矩形的移动?,c#,image-processing,c#-4.0,C#,Image Processing,C# 4.0,我想通过点击按钮在x方向移动矩形,我的图像上有9个矩形,请检查下面的代码,让我知道如何在x或y方向移动所有矩形 我在这里得到了一个新的矩形,但旧的矩形应该消失,所有的矩形必须重叠并在所有方向上一起移动。 我怎样才能做到这一点 private void button2_Click(object sender, EventArgs e) { // listRec has 9 rectangles . Rectangle[] recn = listRec.To

我想通过点击按钮在x方向移动矩形,我的图像上有9个矩形,请检查下面的代码,让我知道如何在x或y方向移动所有矩形

我在这里得到了一个新的矩形,但旧的矩形应该消失,所有的矩形必须重叠并在所有方向上一起移动。 我怎样才能做到这一点

 private void button2_Click(object sender, EventArgs e)
    {
        // listRec has 9 rectangles .
        Rectangle[] recn = listRec.ToArray();

        for (int i = 0; i < 9; i++)
        {

            Rectangle newrec = new System.Drawing.Rectangle();

            newrec.X = recn[i].X + j;
            newrec.Y = recn[i].Y;
            newrec.Width = recn[i].Width;
            newrec.Height = recn[i].Height;
 Rectangle rect = new Rectangle(newrec.X, newrec.Y,newrec.Width, newrec.Height));
                    g.DrawRectangle(Pens.Red, rect);

            pictureBox1.Refresh();
            //ra[0].Location.X = newrec(ra[0].X+10,ra[0].Y,ra[0].Width,ra[0].Height);

        }
        pictureBox1.Invalidate();
        this.Invalidate();


        j = j + 10;
        pictureBox1.Refresh();
    }
private void按钮2\u单击(对象发送者,事件参数e)
{
//listRec有9个矩形。
矩形[]recn=listRec.ToArray();
对于(int i=0;i<9;i++)
{
Rectangle newrec=new System.Drawing.Rectangle();
newrec.X=recn[i].X+j;
newrec.Y=recn[i].Y;
newrec.Width=recn[i].宽度;
newrec.Height=recn[i]。高度;
矩形矩形=新矩形(newrec.X,newrec.Y,newrec.Width,newrec.Height));
g、 DrawRectangle(Pens.Red,rect);
pictureBox1.Refresh();
//ra[0]。位置。X=newrec(ra[0]。X+10,ra[0]。Y,ra[0]。宽度,ra[0]。高度);
}
pictureBox1.Invalidate();
这个。使无效();
j=j+10;
pictureBox1.Refresh();
}

更新所有矩形的位置,然后
Invalidate()
重新绘制图片盒?这里有什么问题?..@Idle_注意,当我试图用鼠标移动矩形时,只有一个矩形在移动,我想移动所有的矩形。我该怎么做呢。我已将所有矩形添加到列表中。你能给我一些进一步做的想法吗。