简体   繁体   English

c#图片框矩阵

[英]c# Matrix of pictureBox

I'm developing a puzzle game for windows mobile.我正在为 windows 手机开发一款益智游戏。 The objetive is to split an image in nine parts and rearrage them to obtain the original image.目的是将一幅图像分割成九个部分并重新排列得到原始图像。 These split images are put on pictureBoxes and these pictureBoxes are redistributed in a matrix of 3X3 cells.这些分割图像放在图片框上,这些图片框重新分布在 3X3 单元的矩阵中。

The user move this cells to arrange them in the correct position (it's a puzzle game.).用户移动这些单元格以将它们排列在正确的 position 中(这是一个益智游戏。)。

I need something to access these pictureBoxes and to know where are they in the matrix.我需要一些东西来访问这些图片框并知道它们在矩阵中的位置。 Suppose that I need to update the image on row 1, column 2 (it's only an example).假设我需要更新第 1 行第 2 列的图像(这只是一个示例)。

In C++ I use pointers to reference object, but I don't know how to do it with C#.在 C++ 中,我使用指针来引用 object,但我不知道如何使用 C# 来实现。

Any advice?有什么建议吗?

Thanks!谢谢!

Just create the matrix with objects that contain the reference to the PictureBox.只需使用包含对 PictureBox 的引用的对象创建矩阵。

MyObject[,] layout = new MyObject[3,3];

public class MyObject
{
        #region attributes        
        private PictureBox pictureBox;
        #endregion

        public MyObject(PictureBox pictureBox)
        {
            this.pictureBox = pictureBox;
        }
}
//This is a reference object
MyCustomObject o1 = new MyCustomObject(imageUrl, row, col);

So from my example I am creating a custom object which holds the url of the image and also a row and column reference.因此,从我的示例中,我创建了一个自定义 object,它包含图像的 url 以及行和列引用。

I can then call:然后我可以打电话:

int row = o1.Row;
int col = o1.Col;
string imageUrl = o1.ImageUrl;

You can then use how you wish.然后,您可以按照自己的意愿使用。

Hope this helps:希望这可以帮助:

Andrew安德鲁

One possible way to do this is to build a puzzle peice class which would hold a reference to the image, it's current position and it's target position.一种可能的方法是构建一个拼图 class ,它将包含对图像的引用,它是当前的 position 和它的目标 position。

public class PuzzlePeice

{
public Bitmap Image {get; }
puliic Point Position {get; set; }
public Point TargetPosition {get; };


}

then assuming peice is an instance of the above class, moving a peice would look like this:然后假设 peice 是上述 class 的一个实例,移动 peice 将如下所示:

peice.Postion = new Point(x,y);

TargetPosition indicates where the peice should be within the matrix for it to form the correct image, this value would of course come from whatever data source you get puzzle info fron and could be set in the constructor TargetPosition 指示 peice 在矩阵中的位置以形成正确的图像,该值当然来自您获得拼图信息的任何数据源,并且可以在构造函数中设置

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM