在Visual C ++中通过PictureBoxes进行迭代 [英] iterating through PictureBoxes in visual c++

查看:69
本文介绍了在Visual C ++中通过PictureBoxes进行迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Visual C ++进行编程,并且有大约60张图片(索引为p0 ... p63).我想做一个遍历所有图片的循环,并在某些情况下更改它们的ImageLocation.

I'm programming in visual c++, and I have about 60 pictures (indexed p0...p63). I want to make a loop that goes through all the pictures and change their ImageLocation under some conditions.

我发现了Tag属性,而我的尝试之一是这样的: 我将照片从0标记为63,然后尝试以下操作:

I figured the Tag property and one of my attempts was like this: I tagged my pictures from 0 to 63 and then tried the following:

for(int i=0; i<64; i++)
{
    PictureBox->Tag[i]->ImageLocation="possible-.gif";
}

它不起作用...我收到此错误:

It's not working... I get this error:

syntax error : missing ';' before '->'        line: 1514
syntax error : missing ';' before '->'        line: 1514

(两次,同一行)

正确的做法是什么?

谢谢!

edit:

好,现在我将图片排列在一个数组中.有没有办法对所有这些人都有共同的规则?我想为每张图片创建一个单击事件.唯一地为每个人设置规则的唯一方法是吗?或者我可以通过说类似以下内容来为数组本身设置规则:

OK now I have the pictures in an array. Is there a way to have a common rule for all of them? I want to make a click event for each and every one of the pictures. Is the only way setting a rule for each independently? Or can I set a rule for the array itself by saying something like:

if(Pictureboxes[i]_Clicked)
{
    Pictureboxes[i].something = "something else";
}

推荐答案

我找到了解决问题的方法.所以我想我要回答自己:

I found the way to solve it. So I guess I'm gonna answer myself:

我制作了一个PictureBoxes数组:

I made an array of PictureBoxes:

private: static array<System::Windows::Forms::PictureBox^>^ pictures=(gcnew array<System::Windows::Forms::PictureBox^>(64));

并在其中填充图片:

pictures[0] = p0;
pictures[1] = p1;
pictures[2] = p2;
...

然后,我单击了每张图片以创建click_events. 在每种情况下,我都输入以下内容:

Then i clicked each of the pictures to create click_events. In each event i typed this:

int place = (/*pic number*/);
IndexOf(pictures);

此代码将发送到我单击的图片的名为IndexOf的函数. 这是IndexOf():

This code sends to a function named IndexOf the picture i clicked. And here is IndexOf():

static System::Void IndexOf(int& place)
{
    int flag = 0;
    if(pictures[place]->ImageLocation == "possible-.bmp")
    {
        flag = 1;
        /*DO CODE*/
    }
    if(flag)
        /*OTHER CODE*/
}

现在,我可以为上面的/执行代码/中的图片[i]做我想做的任何代码.

Now i can do whatever code i want for pictures[i] at /do code/ above.

这篇关于在Visual C ++中通过PictureBoxes进行迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆