Results 1 to 6 of 6

Thread: Can pictureboxes be created during run time?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Red face Can pictureboxes be created during run time?

    Hi,

    Is it possible to create Pictureboxes during run time?

    During design time, there is only 1 picturebox on the form but when the application is running, I would like to add more pictureboxes 'on the fly'.

    Can this be done in vb.net?

  2. #2
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: Can pictureboxes be created during run time?

    Yes, it is possible. I will just post the MSDN example

    VB Code:
    1. Private Sub InitializePictureBox()
    2.     PictureBox1 = New PictureBox
    3.  
    4.     ' Set the location and size of the PictureBox control.
    5.     Me.PictureBox1.Location = New System.Drawing.Point(70, 120)
    6.     Me.PictureBox1.Size = New System.Drawing.Size(140, 140)
    7.     Me.PictureBox1.TabStop = False
    8.  
    9.     ' Set the SizeMode property to the StretchImage value.  This
    10.     ' will shrink or enlarge the image as needed to fit into
    11.     ' the PictureBox.
    12.     Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    13.  
    14.     ' Set the border style to a three-dimensional border.
    15.     Me.PictureBox1.BorderStyle = BorderStyle.Fixed3D
    16.  
    17.     ' Add the PictureBox to the form.
    18.     Me.Controls.Add(Me.PictureBox1)
    19.  
    20. End Sub
    VB 2005, Win Xp Pro sp2

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Re: Can pictureboxes be created during run time?

    Ok.....thanks!

    And to remove the picturebox during run time, the code will be:

    Me.controls.remove(Picturebox1) ?

  4. #4
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: Can pictureboxes be created during run time?

    Hehe, jup. Or simply PictureBox1.visible=false or PictureBox1.hide() if you want to keep it for future uses, references or so. Or PictureBox = Nothing to clear the picture itself.
    VB 2005, Win Xp Pro sp2

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Thumbs up Re: Can pictureboxes be created during run time?

    Yup,ok....thanks for the tips!

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Can pictureboxes be created during run time?

    Don't forget to resolve your thread from the Thread Tools menu.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width