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

using a variable to name a control

AJ
Hi,
I have 20 pictureBoxes named from PictureBox1 to
PictureBox20. I want to fill them up one by one. I'm
keeping a variable firstAvail to keep up with which
pictureBox I should insert the next image into. But how do
I actually access a PictureBox using firstAvail?

I'm thinking I should be able to do something like
PictureBox[firstAvail], but I know that is not the correct
syntax.

Thanks!
Jul 21 '05 #1
4 1559
Why not add the PictureBoxes to a Panel and then you could loop through each
of them without having to know their name up front. You could find out what
the name is as you loop through them.
"AJ" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Hi,
I have 20 pictureBoxes named from PictureBox1 to
PictureBox20. I want to fill them up one by one. I'm
keeping a variable firstAvail to keep up with which
pictureBox I should insert the next image into. But how do
I actually access a PictureBox using firstAvail?

I'm thinking I should be able to do something like
PictureBox[firstAvail], but I know that is not the correct
syntax.

Thanks!

Jul 21 '05 #2
"AJ" <an*******@discussions.microsoft.com> wrote...
I'm thinking I should be able to do something like
PictureBox[firstAvail], but I know that is not the correct
syntax.


Generally speaking you create either a collection or an array of PictureBox
controls and add a reference for each PictureBox to it. Then you have the
ability to address them like you do any collection (or array.) Think about
if you were creating an array of 20 strings and wanted to print the value of
StringArray[ 2 ] it isn't any different to create an array of 20 picture
boxes and to reference the PictureBox reference through the array index.

Tom
Jul 21 '05 #3

"AJ" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Hi,
I have 20 pictureBoxes named from PictureBox1 to
PictureBox20. I want to fill them up one by one. I'm
keeping a variable firstAvail to keep up with which
pictureBox I should insert the next image into. But how do
I actually access a PictureBox using firstAvail?

I'm thinking I should be able to do something like
PictureBox[firstAvail], but I know that is not the correct
syntax.


Create an array of 20 PictureBoxes and loop through it.
Jul 21 '05 #4
AJ,
I would consider using a System.Collections.Queue object to maintain the
list of available PictureBoxes. As a Queue works as a FIFO list.

Queue.Enqueue will add items to the end of the list
Queue.Dequeue will remove items from the front of the list.

Before I added any images I would use the Queue.Enqueue method to load each
PictureBox into the Queue

Private m_available As Queue
Public Sub New()
...
InitializeComponent()

' we know there are 30 picture boxes
m_available = New System.Collections.Queue(20)
m_available.Enqueue(PictureBox1)
m_available.Enqueue(PictureBox2)
...
m_available.Enqueue(PictureBox19)
m_available.Enqueue(PictureBox20)

End Sub

Then when I had a picture to load I would Dequeue the next available
PictureBox.

Public Sub NextPicture(image as Image)
Dim pictureBox as PictureBox = DirectCast(m_available.Dequeue(),
PictureBox)
pictureBox.Image = image
End Sub

This also allows adding a PictureBox back into the list of available
PictureBoxes.

Public Sub FreePicture(pictureBox As PictureBox)
pictureBox.Image = Nothing
m_available.Enqueue(pictureBox)
End Sub

Of course this means that if you use 1 to 5, then 1 becomes available, that
6 to 20 will need to be used before 1 is reused.

Hope this helps
Jay
"AJ" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Hi,
I have 20 pictureBoxes named from PictureBox1 to
PictureBox20. I want to fill them up one by one. I'm
keeping a variable firstAvail to keep up with which
pictureBox I should insert the next image into. But how do
I actually access a PictureBox using firstAvail?

I'm thinking I should be able to do something like
PictureBox[firstAvail], but I know that is not the correct
syntax.

Thanks!

Jul 21 '05 #5

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

Similar topics

17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
5
by: Marcel Gelijk | last post by:
Hi, I am trying to create a User Control that is located in a seperate class library. The User Control contains a textbox and a button. The page generates an exception when it tries to access...
2
by: DocAccolade | last post by:
I am trying to include a legacy com control (controlname.ocx) in an asp.net application using vs 2003. I have added the control to the user control tool box, then dragged it to the form. However,...
15
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with...
3
by: B-Dog | last post by:
I'm capturing the checked radio button to XML file using the name of the radio button. I want to read my xml file to find which button was checked on close and the check the appropriate button...
9
by: KenLee | last post by:
I made an application which includes classic asp page and asp.net page. when I tried to redirect from classic asp page to asp.net 2.0 page, it works under my local IIS directory. ex) <a...
5
by: glenn | last post by:
Hi folks, The problem I have is that a query string works if hard-coded but if I pass a variable to it, it does not work as shown here. This works: querystring="SELECT * FROM USERS WHERE...
7
by: John Smith | last post by:
Hello, I have a simple question, I have a vb.net form with several buttons. If I store the name of a button in a variable.. Dim TheName as string TheName = ...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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)...
0
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

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.