Question Problem creating a new picturebox..

Sebastian133

New member
Joined
Mar 9, 2014
Messages
2
Programming Experience
1-3
VB.NET:
    Public Sub NewPic(ByVal LocX As Integer, ByVal LocY As Integer, ByVal Layer As Integer, ByVal LoadPicture As String, ByVal ImgHeight As Integer, ByVal ImgWidth As Integer, ByVal Initvis As Boolean)

        BG(Layer).Location = New Drawing.Point(LocX, LocY)
        BG(Layer).Image = My.Resources.ResourceManager.GetObject(LoadPicture)
        BG(Layer).Height = ImgHeight
        BG(Layer).Width = ImgWidth
        BG(Layer).Visible = Initvis
        BG(Layer).SizeMode = PictureBoxSizeMode.Normal
        BG(Layer).BringToFront()
        Me.Controls.Add(BG(Layer))

    End Sub

I tried to make a dynamic function for creating pictures.. however, the picture is no shown..
Everything like BringToFront() etc doesnt seem to work, help!
 
You can't bring something to the front when it's not on the form. That said, it should be at the front when you add it. The code doesn't seem to make sense though. The code adds a PictureBox to the form but it doesn't create it. What is BG and why does it exist at all?
 
You can't bring something to the front when it's not on the form. That said, it should be at the front when you add it. The code doesn't seem to make sense though. The code adds a PictureBox to the form but it doesn't create it. What is BG and why does it exist at all?

Well BG is a list of picturebox.

Full code:

VB.NET:
    Public Shared BG As New List(Of PictureBox)

    Private Sub Gamestart(sender As Object, e As EventArgs) Handles MyBase.Shown

        For i As Integer = 0 To 9
            BG.Add(New PictureBox)
        Next
        Threading.Thread.Sleep(1000)
        LocX = 0
        LocY = 0
        Layer = 0
        LoadPicture = "Test"
        ImgHeight = 320
        ImgWidth = 480
        Initvis = True
        NewPic(LocX, LocY, Layer, LoadPicture, ImgHeight, ImgWidth, Initvis)

    End Sub

    Public Sub NewPic(ByVal LocX As Integer, ByVal LocY As Integer, ByVal Layer As Integer, ByVal LoadPicture As String, ByVal ImgHeight As Integer, ByVal ImgWidth As Integer, ByVal Initvis As Boolean)

        BG(Layer).Location = New Drawing.Point(LocX, LocY)
        BG(Layer).Image = My.Resources.ResourceManager.GetObject(LoadPicture)
        BG(Layer).Height = ImgHeight
        BG(Layer).Width = ImgWidth
        BG(Layer).Visible = Initvis
        BG(Layer).SizeMode = PictureBoxSizeMode.Normal
        BG(Layer).BringToFront()
        Me.Controls.Add(BG(Layer))

    End Sub
 
That code doesn't really make a lot of sense. Why is that 'BG' variable Shared for a start and why are you creating those PictureBoxes in code at all? There's nothing dynamic about them because they're exactly the same every time. Why not just create them in the designer?
 
Back
Top