Creating objects during run-time

Newbie Member
16Jul2006,21:18   #1
djvargas's Avatar
I need some help with creating objects while the program is running.

I've noticed that when i am not running the program, when I drag(create) an object on the form, the program automatically makes some code in the "Windows Form Generated Code" region, that resembles "Friend WithEvents ObjectName bla bla bla" among other code below it.

I need a way to click a button and have a NEW picturebox appear in the form, and at the same time, add all that code to the Windows Form Generated Code. Is there a way to do this?

Thanks.
Go4Expert Founder
17Jul2006,10:42   #2
shabbir's Avatar
You have to create an object of the picture box specifying all the properties and it will be placed on the form. Something like

Dim x as new PictureBox
then specify the left,top .... all the prop of x and it should be fine. If you want to add the events you can do that by making a dummy PictureBox and create an object of type picture box.
Newbie Member
18Jul2006,02:07   #3
djvargas's Avatar
I did what you said, but I still don't see a picturebox appearing on the form when I click the button where I have

dim x as new PictureBox
x.top = ...
and the rest of the properties

and nothing seems to happen.
Go4Expert Founder
18Jul2006,23:41   #4
shabbir's Avatar
Here is a link for your problem.
How To Dynamically Add Controls to a Form with Visual Basic 6.0