Adding a control to a form

Kayot

Well-known member
Joined
Mar 6, 2007
Messages
49
Programming Experience
3-5
This is probably simple, but I have no idea how to start.

Desc: I'm making a form that draws a map, thats all done. Now I'm trying to get the form to draw an unknown number of PictureBox(es) and different points on the map in a loop. I'd like to be able to edit the propertys of these controls as they are added.

If thats possible is there a way to make the PictureBoxes delete them selves? (It's a custom control that inherits the picturebox so I can edit the objects internal programs)
 
To add a control to a form:
VB.NET:
Dim pb As New PictureBox

'Set properties here.

Me.Controls.Add(pb)
If you want to be able to keep track of the controls then I suggest that you add them to an array or collection that you can access anywhere via a member variable. To remove the control is much the same:
VB.NET:
Dim pb As PictureBox 'get reference to desired control here.

pb.Dispose()
Me.Controls.Remove(pb)
You may also prefer to use a TableLayoutPanel or FlowLayoutPanel to help you layout the controls appropriately.
 
When I do the following nothing happens. Any idea?

VB.NET:
Dim Point As New imgMapMarker

Point.Left = 100
Point.Top = 100
Point.Height = 9
Point.Width = 9
Point.BackgroundImage = Global.EQemu_Database_Editor.resCommon.Map_Marker
Point.Show()

Me.Controls.Add(Point)
 
Are you trying to embed a form inside another form? If so, I believe you need to add it to the Controls collection before doing .Show().
 
Oh heavens no, I created a custom control that inherits picturebox.

For some reason when I run the above, nothing happens,
 
Are you sure that Global.EQemu_Database_Editor.resCommon.Map_Marker actually refers to an Image object at that point? Have you tried with a different Image? Also, have you tried putting a border around the control so you can see it even if there's no Image? Also, are you absolutely sure that that code is being executed?
 
I used this code and for 1/10th of a second I see an outline then nothing. Any ideas?

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Point As New PictureBox


        Point.Left = 100
        Point.Top = 100
        Point.Height = 9
        Point.Width = 9
        Point.BackgroundImage = Global.EQemu_Database_Editor.resCommon.Map_Marker
        Point.BorderStyle = BorderStyle.FixedSingle
        
        Point.CreateControl()
        Point.Show()
        Me.Controls.Add(Point)


    End Sub
 
If you see the control and then you don't then either you're removing the control, disposing it, setting its Visible property to False or adding another control over the top.
 
Everything I do to it is in my last post. Thats whats bugging me. I don't know why it shows up then poofs.
 
Ok, I'm a tard. I was using a picture box under it without thinking on it. Is there a way to bring my control forward above the picture box?
 
Bring your control forward with the BringToFront method.
 
Back
Top