开发者

Convert a PictureBox to an array in C#

how can i convert and save PictureB开发者_JAVA百科ox into an array, i want to save the place of a PictureBox into an array. Thanks.

For example:

picarray[1,0] = picturebox21
// the place of array = picturebo21

Edited:

I took two dimension array:

PictureBox[,] pic = new PictureBox[8,8];

Now how can i assign parameter to each dimension? (for example i=8,j=8) Thanks.


According to what I understand of your requirements, you want an Array of PictureBoxes. The easiest method to do this is actually an Array of type PictureBox :D

So you begin by defining it

PictureBox[] MyPicBoxArray = new PictureBox[10];

Now you have an array of 10 Picture Boxes.

You can simply use it after that

MyPicBoxArray[0] = MyPictureBox //Already existing PictureBox

Hope this helps :)

UPDATE

Again your intentions are a bit vague.

Setting a value for even a multi-dimension array is almost similar.

You write

PictureBox[,] pic = new PictureBox[x,y];
pic[a,b] = MyExistingPictureBox 
//a and b could be any value where `0 <= a < x` and `0 <= b < y`

If you are talking about assigning something to all the dimensions, then you can use a nested for loop.

int x=3;
int y=3;

for(int i=0; i < x;i++)
{
    for(int j=0; j < y; j++)
    {
       pic[i,j] = SomePictureBox;
       Console.WriteLine(String.Format("[i,j] = [{0},{1}]",i,j));
    }
}

This function will assign SomePictureBox to all dimensions of pic and will output

[i,j] = [0,0]
[i,j] = [0,1]
[i,j] = [0,2]
[i,j] = [1,0]
[i,j] = [1,1]
[i,j] = [1,2]
[i,j] = [2,0]
[i,j] = [2,1]
[i,j] = [2,2]


The following CodeProject article shows how to convert an Image shown in PictureBox to an Array.

Sending/Receiving PictureBox Image in C# To/From Microsoft SQL SERVER

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜