在 C# 中将 PictureBox 转换为数组

发布于 2024-10-05 14:51:54 字数 313 浏览 3 评论 0原文

我如何将 PictureBox 转换并保存到数组中,我想将 PictureBox 的位置保存到数组中。谢谢。

例如:

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

编辑:

我采用了二维数组:

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

现在我如何为每个维度分配参数? (例如i=8,j=8)谢谢。

how can i convert and save PictureBox 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪冰清 2024-10-12 14:51:54

根据我对您的要求的了解,您需要一个图片框数组。最简单的方法实际上是一个 PictureBox 类型的数组:D

所以你首先定义它

PictureBox[] MyPicBoxArray = new PictureBox[10];

现在你有一个包含 10 个图片框的数组。

之后您就可以简单地使用它

MyPicBoxArray[0] = MyPictureBox //Already existing PictureBox

希望这有帮助:)

更新

您的意图再次有点模糊。

即使为多维数组设置值也几乎类似。

如果您正在谈论

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`

为所有维度分配某些内容,那么您可以使用嵌套的 for 循环。

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));
    }
}

该函数会将 SomePictureBox 分配给 pic 的所有尺寸并输出

[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]

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]
凉城 2024-10-12 14:51:54

以下 CodeProject 文章展示了如何将 PictureBox 中显示的图像转换为 Array

在 C# 中向 Microsoft SQL SERVER 发送/接收 PictureBox 图像

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文