473,386 Members | 1,791 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,386 software developers and data experts.

Dynamic Object Naming

How do I change this :

this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.pictureBox4 = new System.Windows.Forms.PictureBox();
this.pictureBox5 = new System.Windows.Forms.PictureBox();

To This:

for (int i = 1; i < 6; i++)
{
this.pictureBox+(i) = new System.Windows.Forms.PictureBox();
}

Do i need to put it into an array or something? Thanks for any help ...

Nov 16 '06 #1
3 1754
TheLostLeaf wrote:
How do I change this :

this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.pictureBox4 = new System.Windows.Forms.PictureBox();
this.pictureBox5 = new System.Windows.Forms.PictureBox();

To This:

for (int i = 1; i < 6; i++)
{
this.pictureBox+(i) = new System.Windows.Forms.PictureBox();
}

Do i need to put it into an array or something? Thanks for any help ...
Hi,

An array would be the way to go:

/// At the top somewhere
private PictureBox[] pictureBox = new PictureBox[6];
///

/// In your code somewhere
for ( int i = 0; i < pictureBox.Length; i++ )
this.pictureBox[i] = new PictureBox();
///

Note that arrays are zero-based.

--
Hope this helps,
Tom Spink

Google first, ask later.
Nov 16 '06 #2
Hi,
you are right, just put your picture boxes in an array:

const int numberOfPictureBoxes = 5;
PictureBox[] pictureBoxes = new PictureBox[numberOfPictureBoxes];
for(int i=0; i<numberOfPictureBoxes; ++i)
{
pictureBoxes[i] = new PictureBox();
}

HTH
Mark.
--
http://www.markdawson.org
"TheLostLeaf" wrote:
How do I change this :

this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.pictureBox4 = new System.Windows.Forms.PictureBox();
this.pictureBox5 = new System.Windows.Forms.PictureBox();

To This:

for (int i = 1; i < 6; i++)
{
this.pictureBox+(i) = new System.Windows.Forms.PictureBox();
}

Do i need to put it into an array or something? Thanks for any help ...

Nov 16 '06 #3
That got me on the right track.

/// I put this in the class
private System.Windows.Forms.PictureBox[] pictureBox;

///i put this in the funciton
pictureBox = new System.Windows.Forms.PictureBox[10];

for ( int i = 0; i < pictureBox.Length; i++ )
{
this.pictureBox[i] = new
System.Windows.Forms.PictureBox();

((System.ComponentModel.ISupportInitialize)(this.p ictureBox[i])).BeginInit();
}
Works perfect,,, Thanks !
Tom Spink wrote:
TheLostLeaf wrote:
How do I change this :

this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.pictureBox4 = new System.Windows.Forms.PictureBox();
this.pictureBox5 = new System.Windows.Forms.PictureBox();

To This:

for (int i = 1; i < 6; i++)
{
this.pictureBox+(i) = new System.Windows.Forms.PictureBox();
}

Do i need to put it into an array or something? Thanks for any help ...

Hi,

An array would be the way to go:

/// At the top somewhere
private PictureBox[] pictureBox = new PictureBox[6];
///

/// In your code somewhere
for ( int i = 0; i < pictureBox.Length; i++ )
this.pictureBox[i] = new PictureBox();
///

Note that arrays are zero-based.

--
Hope this helps,
Tom Spink

Google first, ask later.
Nov 16 '06 #4

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

Similar topics

6
by: alexandre damiron | last post by:
Did anyone tried dynamic variable naming in Js, like the ${$varname} feature of PHP ? It would easier a long DOM generation, for example to place such a code portion into a loop .... ...
12
by: Chad Z. Hower aka Kudzu | last post by:
Object MyOnject = new Object; What does the signify? -- Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/ "Programming is an art form that fights back"
1
by: Steve Booth | last post by:
I have a web form containing a button that when selected adds a user control to a place holder. The user control contains a button. The first time the user control is added the contained button...
5
by: vivekian | last post by:
Have to create a linked list of objects of the same type based on user input. The number of objects in the list is dynamic depending on the number input from the user. What would be the best way to...
4
by: Zark3 | last post by:
Hi all, I was wondering if anybody could enlighten me on the possibility of dynamic casting. Or, well, whether or not I'm actually trying to do this the right way. What I have is a base class...
22
by: Cylix | last post by:
I have a 4row x 1col table, I would like to drop all the content of row three. Since Mac IE5.2 does not suppport deleteRow method, I have also try to set the innerHTML=''; but it does not work. ...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
3
by: SPECTACULAR | last post by:
Hi all. I have a question here.. what kind of scoping does C++ use? and what kind does Smalltalk use? I know smalltalk is a little bit old .. but any help would be appreciated.
1
by: Puja | last post by:
hi all, On my page, i have external stylesheet <link id="sbSiteCSS" rel="stylesheet" type="text/css" runat="server" /> whose href is determined on page_load protected void Page_Load(object...
8
by: machoq | last post by:
Hi folks, I have a javascript object called record and i want to pass the field name dynamically. Something like print(record.$field) It always gives me null, what can i do so that it prints...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.