Home All Groups Group Topic Archive Search About

Attaching controls in runtime...

Author
16 Jan 2006 6:20 PM
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

Author
16 Jan 2006 6:39 PM
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()


Show quoteHide quote
"Knight" <warhawk0***@sbcglobal.net> wrote in message
news:1137435607.003085.64130@g43g2000cwa.googlegroups.com...
>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
>
Author
16 Jan 2006 6:58 PM
Knight
Thank you very much, I was missing Suspend/Resume
Author
16 Jan 2006 7:53 PM
Herfried K. Wagner [MVP]
"Knight" <warhawk0***@sbcglobal.net> schrieb:
> Thank you very much, I was missing Suspend/Resume

Mhm...  This should not make such a big difference.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>