PDA

Click to See Complete Forum and Search --> : Creating PictureBoxes as run time???


Oct 30th, 2000, 11:45 PM
Hi all.

Is it possible to create new instances of a PictureBox? Like you do for a Form?

I tried the following code:

Dim Pic as PictureBox 'That works well
Set Pic = New PictureBox 'That does not work at all!


What am I doing wrong here?

Thanks.

ohmhalia
Oct 31st, 2000, 01:05 AM
The first line is enough. No need the second line. TQ

Oct 31st, 2000, 12:47 PM
I tried it, and it doesn't create a PictureBox, it creates a "pointer" to a picturebox pointing on "Nothing". So when entering:


pic(i).Scalewidth = 100 'for example


I get the following error:

"Object variable or With Block variable not set."


Any suggestions?

MoMad
Oct 31st, 2000, 03:54 PM
What you do is...

First you create a picturebox and name it picNameOfPic (or whatever)

and you set the Index value to 0 and set the visibility to true(at design time)

then you put the following code in your program...



Dim i As Integer

For i = 0 to 10
'Note that picNameOfPic(0) is already loaded and thus
'would generate an error if you try to load it again...
'However, if you do wanna 'reload' it, you might want to
'consider unloading it the same way as u loaded it.
'Example:
'Unload picNameOfPic(i)
'Its simple actually...

If i Then 'i <> 0
Load picNameOfPic(i)
picNameOfPic(i).Visible = True
picNameOfPic(i).Left = picNameOfPic(i - 1).Left + 100 'Move Right 100
picNameOfPic(i).Top = picNameOfPic(i - 1).Top + 100 'Move Down 100
'etc....
End If

'If you want to load an Image into those pics...
picNameOfPic.Picture = LoadPicture(App.Path & "/imageName.gif")
Next i



If you still need any Help you can ask me whatever the problem is...

Good Luck with this one...

Oct 31st, 2000, 04:18 PM
Thanks Man!

Sorry again for the wrong reply on the other thread...


Ciao!

MoMad
Oct 31st, 2000, 06:53 PM
no, no... its cool.

No need to appoligize, u did ur best to help.

And now u just learned something new... thats what programming is all about.