1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating objects during run-time

Discussion in 'Visual Basic ( VB )' started by djvargas, Jul 16, 2006.

  1. djvargas

    djvargas New Member

    Joined:
    Jul 11, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    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.
     
  3. djvargas

    djvargas New Member

    Joined:
    Jul 11, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83

Share This Page