473,758 Members | 7,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.publi c.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::Compone ntModel;
using namespace System::Collect ions;
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)
{
InitializeCompo nent();
//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows ::Forms::Pictur eBox^ pictureBox1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::Compone ntModel::Contai ner ^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 InitializeCompo nent(void)
{
this->pictureBox1 = (gcnew
System::Windows ::Forms::Pictur eBox());

(cli::safe_cast <System::Compon entModel::ISupp ortInitialize^

(this->pictureBox1) )->BeginInit();
this->SuspendLayout( );
//
// pictureBox1
//
this->pictureBox1->Location =
System::Drawing ::Point(70, 44);
this->pictureBox1->Name = L"pictureBox 1";
this->pictureBox1->Size =
System::Drawing ::Size(100, 50);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Click += gcnew
System::EventHa ndler(this,
&Form1::picture Box1_Click);
//
// Form1
//
this->AutoScaleDimen sions =
System::Drawing ::SizeF(6, 13);
this->AutoScaleMod e =
System::Windows ::Forms::AutoSc aleMode::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::Compon entModel::ISupp ortInitialize^
(this->pictureBox1) )->EndInit();

this->ResumeLayout(f alse);

}
#pragma endregion
private: System::Void pictureBox1_Cli ck(System::Obje ct^
sender,
System::EventAr gs^ e) {
}
};

Mar 20 '06 #1
4 9233
> Hello Everyone,
I have been gettting great feedback from microsoft.publi c.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 InitializeCompo nent method you have to
initialize your array of images:
CurrentImage = 0;

imageArray = gcnew array<Image^>(1 3);

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************* *********@hotma il.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::Drawin g::Image^
(resources->GetObject(L"pi ctureBox1.Image ")));

this->pictureBox1->Location = System::Drawing ::Point(93, 69);
this->pictureBox1->Name = L"pictureBox 1";
this->pictureBox1->Size = System::Drawing ::Size(100, 100);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Click += gcnew System::EventHa ndler(this,
&Form1::picture Box1_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::Compone ntModel::Compon entResourceMana ger^ resources =
(gcnew
System::Compone ntModel::Compon entResourceMana ger(Form1::type id));

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

//load each image into the array.
for(int i=0; i<13; i++)
{
imageArray[i] =(cli::safe_cas t<System::Drawi ng::Image^ >
(resources->GetObject(name s[i])));
}

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

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.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
9507
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 draw (but for specific uses). What I need to be able to do is import graphics and text and then move them around the background until they are where I want them and then export it out as an image file. The problem is that I need to be able to...
2
2962
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 scroll the 30 forms vertically in sort of a "film clip" like method. Can anyone give a little insight into what, if any, container is capable of holding 30 different form objects each with its own data?
1
3920
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 make it easier for someone (i.e. a Microsoft person) to digest the information and respond to it. I am a C++ and Java developer with over 3 years of industry experience. I've written low level C++ code, in addition to web clients that use web...
2
1863
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 by the position on the list) this is so i can then pass it to the array called pictureimage to get the correct filename (similar to the picturetext part of this routine) and then the final line on the fuction is to change an original image with...
23
16437
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 wrong?
17
7253
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 to show the array data to the end user. Can I do that? How?
1
1638
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 a PictureBox, using code like this: g = PictureBox1.CreateGraphics() p = New Pen(char_color, pen_width) p.LineJoin = Drawing2D.LineJoin.Round
5
3796
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);" I thought that it is very hard to memory map structure array. I need both read and write memory mapped file at both side of C# and C++.
3
4846
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 pointers (delegates). I assume I need to use the array< T keyword to allocate an array of delegates, and then initialize the array by setting each array element to the pointers (handles) of the functions I'll be invoking. I've been trying to...
0
9506
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9317
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10090
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9758
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7310
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6580
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3844
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.