473,503 Members | 9,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Picturebox Array (VB Express)

Hi there,

Is it possible to create an array of picturebox controls during
run-time. I wish to create a new image/picturebox everytime a user
clicks the button on a form, and they need to be objects so that the
user can move/drag them around.
The only examples I can find dont work as I am using VB Express (2005?)

and the examples are writting in VB6.
Is anyone able to help please?
Toby.

Jan 4 '07 #1
5 4534
At class level in your form:

Private m_pictureboxes As New ArrayList()

In the Click event handler of your button:

Dim _pic As New PictureBox

_pic.Location = New System.Drawing.Point(<x>, <y>)

_pic.Size = New System.Drawing.Size(<w>, <h>)

' set any other properties as required

' wire up the desired event handlers
AddHandler _pic.<event>, AddressOf <event_handler>

Me.Controls.Add(_pic)

m_pictureboxes.Add(_pic)

where:

<xand <yare the coordinates of the desired iniial position
<wand <hare the width and height values for the desired size
<eventis the desired event
<event_handleris the desired event hander (predefined)

e.g.

Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

CType(sender, PictureBox).BackColor = Color.CadetBlue

End Sub

If you 'add' 3 pictureboxes by clicking the button three times and then
click a picturebox, it's background colour will change.

Obviously you will have to implement a mechanism for varying the <xand <y>
values otherwise all the pictureboxes will be drawn in the same place.
<to**@mkkbb.f9.co.ukwrote in message
news:11**********************@31g2000cwt.googlegro ups.com...
Hi there,

Is it possible to create an array of picturebox controls during
run-time. I wish to create a new image/picturebox everytime a user
clicks the button on a form, and they need to be objects so that the
user can move/drag them around.
The only examples I can find dont work as I am using VB Express (2005?)

and the examples are writting in VB6.
Is anyone able to help please?
Toby.

Jan 4 '07 #2
Toby,

Instead of the label1 and label2 you can use pictureboxes

http://www.vb-tips.com/dbpages.aspx?...1-47ef665ea0c2

Cor
<to**@mkkbb.f9.co.ukschreef in bericht
news:11**********************@31g2000cwt.googlegro ups.com...
Hi there,

Is it possible to create an array of picturebox controls during
run-time. I wish to create a new image/picturebox everytime a user
clicks the button on a form, and they need to be objects so that the
user can move/drag them around.
The only examples I can find dont work as I am using VB Express (2005?)

and the examples are writting in VB6.
Is anyone able to help please?
Toby.

Jan 4 '07 #3
Thanks very much for the responses, looks like I was almost there, but
your examples have been a godsend! :-)

Thanks again.

Jan 4 '07 #4

Stephany Young wrote:
At class level in your form:

Private m_pictureboxes As New ArrayList()

In the Click event handler of your button:

Dim _pic As New PictureBox

_pic.Location = New System.Drawing.Point(<x>, <y>)

_pic.Size = New System.Drawing.Size(<w>, <h>)

' set any other properties as required

' wire up the desired event handlers
AddHandler _pic.<event>, AddressOf <event_handler>

Me.Controls.Add(_pic)

m_pictureboxes.Add(_pic)

where:

<xand <yare the coordinates of the desired iniial position
<wand <hare the width and height values for the desired size
<eventis the desired event
<event_handleris the desired event hander (predefined)

e.g.

Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

CType(sender, PictureBox).BackColor = Color.CadetBlue

End Sub

If you 'add' 3 pictureboxes by clicking the button three times and then
click a picturebox, it's background colour will change.

Obviously you will have to implement a mechanism for varying the <xand <y>
values otherwise all the pictureboxes will be drawn in the same place.
<to**@mkkbb.f9.co.ukwrote in message
news:11**********************@31g2000cwt.googlegro ups.com...
Hi there,

Is it possible to create an array of picturebox controls during
run-time. I wish to create a new image/picturebox everytime a user
clicks the button on a form, and they need to be objects so that the
user can move/drag them around.
The only examples I can find dont work as I am using VB Express (2005?)

and the examples are writting in VB6.
Is anyone able to help please?
Toby.
Stepahnie,

How can I reference the image property of a picturebox in an array. I
would ahve assumed it was:

m_picturebox(1).image

but that brings up errors. How can I change properties of these
controls in the array?

Thanks.

Jan 4 '07 #5
What 'errors'?
<to**@mkkbb.f9.co.ukwrote in message
news:11*********************@i80g2000cwc.googlegro ups.com...
>
Stephany Young wrote:
>At class level in your form:

Private m_pictureboxes As New ArrayList()

In the Click event handler of your button:

Dim _pic As New PictureBox

_pic.Location = New System.Drawing.Point(<x>, <y>)

_pic.Size = New System.Drawing.Size(<w>, <h>)

' set any other properties as required

' wire up the desired event handlers
AddHandler _pic.<event>, AddressOf <event_handler>

Me.Controls.Add(_pic)

m_pictureboxes.Add(_pic)

where:

<xand <yare the coordinates of the desired iniial position
<wand <hare the width and height values for the desired size
<eventis the desired event
<event_handleris the desired event hander (predefined)

e.g.

Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

CType(sender, PictureBox).BackColor = Color.CadetBlue

End Sub

If you 'add' 3 pictureboxes by clicking the button three times and then
click a picturebox, it's background colour will change.

Obviously you will have to implement a mechanism for varying the <xand
<y>
values otherwise all the pictureboxes will be drawn in the same place.
<to**@mkkbb.f9.co.ukwrote in message
news:11**********************@31g2000cwt.googlegr oups.com...
Hi there,

Is it possible to create an array of picturebox controls during
run-time. I wish to create a new image/picturebox everytime a user
clicks the button on a form, and they need to be objects so that the
user can move/drag them around.
The only examples I can find dont work as I am using VB Express (2005?)

and the examples are writting in VB6.
Is anyone able to help please?
Toby.

Stepahnie,

How can I reference the image property of a picturebox in an array. I
would ahve assumed it was:

m_picturebox(1).image

but that brings up errors. How can I change properties of these
controls in the array?

Thanks.

Jan 4 '07 #6

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

Similar topics

15
5301
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
11
2243
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
4
9189
by: Charles | last post by:
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...
0
1217
by: akumarp2p | last post by:
Hi Experts I have created a panel at design time. At Run time i make array of PictureBox and add image to that pictureBox array control. Now I have problem, How to Create Event on that dynamin...
0
937
by: Feride | last post by:
hello, i'm trying to show a pictureBox named pb1 on some other pictureBoxes which are the elements of a pictureBox array called pbs. To watch the differences, i made use of a timer. here are the...
6
25762
by: robusto33 | last post by:
Hi everyone, I'm really new to C#.net development, especially for win32 applications. I'm basically making a board game and was wondering if anyone could help me out with this predicament: I have...
2
2808
by: Boki | last post by:
Hi All, I remember in VB6, we can create any component array just by copy and paste, and the IDE will ask us to use a component array or not. I did the same thing on C#, it will auto create the...
4
3793
by: munibe | last post by:
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button, my wish is to add a new small...
4
3687
by: Jim McGivney | last post by:
In C# on Form1 I genetate an array of PictureBoxes and populate each with an image as seen in the code below. Later on I want to access a specific PictureBox to change its image, but I keep...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7470
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...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4693
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...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
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 ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.