Creating objects during run-time

djvargas's Avatar
Newbie Member
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
0
djvargas's Avatar
Newbie Member
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Here is a link for your problem.
How To Dynamically Add Controls to a Form with Visual Basic 6.0