Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create PictureBox at runtime 1

Status
Not open for further replies.

Terabithia

Programmer
Aug 31, 2004
70
0
0
US
I need to be able to create additional PictureBox controls at runtime in VB.net script, there will be one PictureBox already on the form. I then need to position it relevant to the previous one. I will have the path and name for the image files and I know how to load that to the control. At design time I will not know how many of the PictureBox controls need to be created.

Can anyone point me in the right direction?
 
A bit of code to get you started.

Dim pb As PictureBox
Dim ThisPicBoxLeft As Integer

pb = New PictureBox

pb.Name = "NameHere"

ThisPicBoxLeft = PictureBox1.Left + PictureBox1.Width + 10 'assumes PictureBox1 is the one that is already on the form. Add 10 to put some space between the 2

pb.Left = ThisPicBoxLeft
pb.Top = PictureBox1.Top

Me.Controls.Add(pb) 'add the picturebox to the form


When adding more picture boxes:

ThisPicBoxLeft = ThisPicBoxLeft + pb.Width + 10


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Jebenson,

Thanks! That was what I needed, got it working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top