Hi, I have a little project to do relating picture boxes in visual c++. I have googled for very long and cant find a solution.

I have a picture box with 3 buttons, previous, play pause and next.

It involves a timer control which will run and enable the slideshow. I have to also be able to use the next and previous buttons for switching between the pictures.

The pictures have to be loaded from a folder that I specify, I saw somewhere that you can add the pictures to an array, thats not what i want, I need the program to select the pictures from the folder I specify one by one each time I choose the next button or the timer increments.

Well, could you do a search through the folder then add them to an array, then cycle through on the picture box?

You won't need to store the images in an array. all you need is the path to each image file, and store that in a vector, which gives you much more options adding, removing, replacing, etc. You could even go the extra step of having a class that stores the name, the path, the metadata, etc., of each image, and make a vector of that class.

The part of specifying each image individually is what I want to avoid. it needs to automatically update as thers 4 sets of that i need to do, I need to switch between them with radio boxes.

The part about automatically scanning a folder on startup and adding the pics to the array should work, how will I tell it to index a folder and then add it to the array, so far I have only done manual arrays and reading from a text file with a loop, how to do it with files in a folder?

In the example you linked to. The first thing it does is make an array of the image file paths. Telling the array which file paths to load is fairly simple, and can be done automatically by handling the radiobuttons checked changed event. If you're using CLR the code from c# will convert fairly easily. Some of the syntax will be a bit different though.

Thanks sofar for the help, this is what I think needs to happen and what I know sofar:

In the past I used a loop to load data into the array as follows:

void ReadFromFile(Movies Films[], int& Size)
{
    ifstream inFile;
    Size = 0;


    inFile.open("Flieks.txt");

    if (!inFile)
    {
        cout << "ERROR: File does not exist: " << endl << endl;
        cout << "Please make sure that the text file \"Flieks.txt\" exists" << endl 
        << "in the program's Directory." << endl << endl;
        system("pause");
        exit(1);
    }
    else
        {
             inFile >> Films[Size].Code    >> Films[Size].Title
                    >> Films[Size].Copies  >> Films[Size].OnShelf
                    >> Films[Size].Deposit >> Films[Size].CashBack;

                while (!inFile.eof())
                {
                     Size++;
                     inFile >> Films[Size].Code    >> Films[Size].Title
                            >> Films[Size].Copies  >> Films[Size].OnShelf
                            >> Films[Size].Deposit >> Films[Size].CashBack;
                }
        }
    inFile.close();
}

I need to construct something similar for this, that was just plain cli, part of a videorentals program I did in university.

//this is the array, it looks different to the arrays Im used to. 
string [] part1=null;

//I know a array as this:
int max =10
string array1[max];

while(i < max)
   {
    cin >> array1[i];
    i++;
   }

//part1 is the array name I guess
part1 = Directory.GetFiles(folderBrowserDialog1.SelectedPath,"*.jpg");

I guess I can rewrite the above statement as follows:

string folder ="c:\\users\\hardus\\pictures";
part1 = Directory.Getfiles(folder,"*.jpg");

This whole thing gets overly confused, they have lots of stuff that unnececary in there.
Im going to write the code here as I think it should go:

//global variables
int max =0
string array1[max];
int i =0;

 //radio button code ( I will also load this code at the app startup as its only acticated 
 on the radio button click.)

string folder ="c:\\users\\hardus\\pictures";

while(folder != null)
{
    array1[i] = Directory.Getfiles(folder,"*.jpg");
    i++;
    max++;
}

//Next button code
while(i < max)
   {
    pictureBox1.Image = array1[i];
    i++;
   }

The main difference with cli code and standard code is your using code from specific libraries. Otherwise syntactically they're the same.

Im taking this step by step.

I started and figured out to declare an array.

Now I just for a test created an empty label wherein to display the names I put in the array.

I declared the array under:

public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here

array<String^>^ names = gcnew array<String^>(9) {
"Andre", "Crespo", "Iribarren",
    "Jimenez", "Moran", "Palaveccino", "Simon",
    "Torres", "Urdaneta"};

int i = 0;

I placed this code under the button:

         while(i < 9)
         {
         label1->Text = names[i];

         i++;
         }

Theoretically once the button is pressed the label will show the first name in the array, then the second time its pressed the second name, etc. I need to get this working in order to continue my testing and get to the next step where ill add a timer and have it circulate the names when I press play.

The main problem your having is scope. when you declare objects in a block no other block outside that one can see it. Make your objects class level and your code should work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.