473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Newebie: How do I change a Picture Box on a Visual C++ / CLR managed form into a picture box array?

Hello Everyone,
I have been gettting great feedback from microsoft.public.vc.language
group but after doing more searching I think my post should be directed
to this group.

I am trying to make a simple gif animation using VC++ and 13 different
gif files and a timer.
I am new to VC++ but played around with C++ for a few years. I am
using Microsoft Visual Studio 2005 (VC++).

Before I was using 13 different picturebox controls but have been told
that I should use a picturebox array instead.

I have found many exmaples on how to make a String array however I am
having a difficult time changing a picturebox control into a picturebox
array. I have started a new form and a single picturebox control. I
have been trying to figure out how to change the declaration to make it
into an array. However, I have had no luck this far. Below is a cut
and paste
of the new form with a single picturebox. If anyone could help me to
understand how to accomplish this I would be grateful.

Thank you,
Charles
--------------------------------------------------------------
#pragma once

namespace ex {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will
need to change the
/// 'Resource File Name' property for the managed
resource compiler tool
/// associated with all .resx files this class depends
on. Otherwise,
/// the designers will not be able to interact
properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^

(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Location =
System::Drawing::Point(70, 44);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(100, 50);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Click += gcnew
System::EventHandler(this,
&Form1::pictureBox1_Click);
//
// Form1
//
this->AutoScaleDimensions =
System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(295,
266);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->pictureBox1))->EndInit();

this->ResumeLayout(false);

}
#pragma endregion
private: System::Void pictureBox1_Click(System::Object^
sender,
System::EventArgs^ e) {
}
};

Mar 20 '06 #1
4 9158
> Hello Everyone,
I have been gettting great feedback from microsoft.public.vc.language
group but after doing more searching I think my post should be directed
to this group.

I am trying to make a simple gif animation using VC++ and 13 different
gif files and a timer.
I am new to VC++ but played around with C++ for a few years. I am
using Microsoft Visual Studio 2005 (VC++).

Before I was using 13 different picturebox controls but have been told
that I should use a picturebox array instead.

I have found many exmaples on how to make a String array however I am
having a difficult time changing a picturebox control into a picturebox
array. I have started a new form and a single picturebox control. I
have been trying to figure out how to change the declaration to make it
into an array. However, I have had no luck this far. Below is a cut
and paste
of the new form with a single picturebox. If anyone could help me to
understand how to accomplish this I would be grateful.

Hi,

There is an easy way to do this:
declare a member variable like this:
array<Image^> ^imageArray ;

int CurrentImage;

Then in your constructor, after the InitializeComponent method you have to
initialize your array of images:
CurrentImage = 0;

imageArray = gcnew array<Image^>(13);

for(int i=0; i< imageArray->Length ; i++)

{

//initialize image array

}

And finally, In your timer function you do this:
if(CurrentImage >= imageArray->Length -1)

CurrentImage = 0;

else

CurrentImage++;

pictureBox1->Image = imageArray[CurrentImage];

That way your picturebox cycles through your image collection without much
programming on your part.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Mar 20 '06 #2
Thank you Bruno for your help.

In order to initialize the array would I still need to create 13
different picturebox objects in order to embed them into the Form1.resX
file?

Also in the area where I initialize the array using the IF (not end of
array) statement what would the best way to add the information for
each of the images (GIF files)? Below is an example of the pictureBox
with one file. I think I sould be able to reuse everything below with
the exception of the first line showing the image name.

------------------------------------
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^
(resources->GetObject(L"pictureBox1.Image")));

this->pictureBox1->Location = System::Drawing::Point(93, 69);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(100, 100);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Click += gcnew System::EventHandler(this,
&Form1::pictureBox1_Click);

------------------------------------
thank you for any additional help you have already do so much.

Best regards,
Charles

Mar 20 '06 #3
> In order to initialize the array would I still need to create 13
different picturebox objects in order to embed them into the Form1.resX
file? No. You can manually add the images to your resource with the resource
editor. You can use whatever format you like. it depends on the desired
image quality. Just make sure it is one of the supported types

Also in the area where I initialize the array using the IF (not end of
array) statement what would the best way to add the information for
each of the images (GIF files)? Below is an example of the pictureBox
with one file. I think I sould be able to reuse everything below with
the exception of the first line showing the image name.


Yopu don't need extra picturebox objects.
For initializing the array you can do something like this:

//get handle to resource manager
System::ComponentModel::ComponentResourceManager^ resources =
(gcnew
System::ComponentModel::ComponentResourceManager(F orm1::typeid));

array<String^>^ names = {L"image_1.Image", .... ,"image_13.Image"};
//13 image resource names

//load each image into the array.
for(int i=0; i<13; i++)
{
imageArray[i] =(cli::safe_cast<System::Drawing::Image^ >
(resources->GetObject(names[i])));
}

And then just change the image in your timer function like i demonstrated in
my previous mail.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Mar 20 '06 #4
Hello Bruno,
I just wanted to take a minute to say thank you for all your help.
Your a true Pro!!

Charles

Mar 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Chris Coho, Jr. | last post by:
Ok, I'll explain the whole problem because there may be several ways to solve this and hopefully someone knows one. What I'm doing is creating a specialty template editor, similar to say a corel...
2
by: Woof-Woof | last post by:
Hi, I have an application which displays a form with bar graph data on it. What I need to do is string 30 of these bar graph forms vertically in a picture box or some other container so I can...
1
by: Novice | last post by:
Hi all, I'm afraid this is the second posting of this information as I didn't get a response on the previous post. I will try to shorten my message (i.e. be more concise) in the hopes that it will...
2
by: Nick Calladine | last post by:
Is this possible to ... I wish to get the value of a dropdown select but gets is indexable value (dont know if that is the right term) if that is possible (the position it assigned get assigned...
23
by: Gerrit | last post by:
Hi all, I'm getting an OutOfMemoryException when I initialize a byte array in C# like this: Byte test = new Byte; I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: =?Utf-8?B?UEsgRmVycmljaw==?= | last post by:
Hi all, My first post to MSDN... I've recently started to get into VB.NET, having been a casual VB user for a few years. So far, it's going OK. I've managed to figure out how to draw lines on...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
3
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.