Attaching controls in runtime...

K

Knight

I recently converted to VB Net from VB 6 and having troubles with
adding a PictureBox to the form. I create the picturebox but it
doesn't display on my form. I have tried Controls.Add(pic)
but that doesn't work either. Any Help would be much appreciated :).

here is my code so far

Knight

Function CreateSurface(ByVal frm As Form) As PictureBox
Dim pic As New PictureBox
Dim loc As Point

loc.X = frm.Location.X
loc.Y = frm.Location.Y

pic.Name = "surface"
pic.Location = loc
pic.Left = frm.Left
pic.Top = frm.Top
pic.Width = frm.Width
pic.Height = frm.Width
pic.BackColor = Color.Black
pic.Visible = True


pic.Show()
CreateSurface = pic
End Function
 
A

AMDRIT

this seems to work for me


Dim pic As PictureBox
pic = New PictureBox
Me.SuspendLayout()

pic.BackColor = System.Drawing.Color.FromKnownColor(KnownColor.Black)
pic.Size = New System.Drawing.Size(50, 50)
pic.BorderStyle = BorderStyle.Fixed3D
pic.Location = New System.Drawing.Point(60, 60)

Me.Controls.Add(pic)

Me.ResumeLayout()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top