Solved

Array of PictureBox

Posted on 2011-03-07
4
804 Views
Last Modified: 2012-05-11
I'm new to vb.Net and I'm trying to create a array of picture boxes.  That I will need to place an external application in.  I will also need the events of the picture box

I'm using the code below

Public Class Form1
Dim newPB() As PictureBox


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        i = 2
        Dim newPB(i) As PictureBox
        For i = 0 To 2
            newPB(i) = New PictureBox
            With newPB(i)
                .Top = 230
                .Width = 230
                If i > 0 Then
                    .Left = newPB(i - 1).Left + newPB(i - 1).Width + 6
                Else
                    .Left = 3
                End If
                .Height = 200
                .Parent = Me
                .BorderStyle = BorderStyle.Fixed3D
                .Visible = True
            End With
        Next
    End Sub

When I try to get the
MsgBox(newPB(0).Handle)

I get the following message
Use the "new" keyword to create an object instance

If I am going about it the wrong way please feel free to correct.

Any help would be appreciated.
0
Comment
Question by:PhilChapmanJr
  • 3
4 Comments
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 35063708
Dim newPB() As PictureBox

to

Dim newPB(2) As New PictureBox

0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 35063709
Change the code

Dim newPB() As PictureBox

to

Dim newPB(2) As New PictureBox

0
 
LVL 8

Accepted Solution

by:
PagodNaUtak earned 500 total points
ID: 35063725
Or you can optimize your code by using generic list instead...

Try something like the code below:


Public Class Form1
Dim newPB() As New List(Of PictureBox)


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        i = 2
        Dim newPB(i) As PictureBox
        For i = 0 To 2
            newPB(i) = New PictureBox
            With newPB(i)
                .Top = 230
                .Width = 230
                If i > 0 Then
                    .Left = newPB(i - 1).Left + newPB(i - 1).Width + 6
                Else
                    .Left = 3
                End If
                .Height = 200
                .Parent = Me
                .BorderStyle = BorderStyle.Fixed3D
                .Visible = True
            End With
        Next
    End Sub

Open in new window

0
 
LVL 2

Author Closing Comment

by:PhilChapmanJr
ID: 35064124
Thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now