Dynamicly adding and removing panels

  • Thread starter Thread starter Dan Smith
  • Start date Start date
I'm developing a small game that uses panels as objects. I'm stuck figuring out how to, on the fly, create multiple panels of same color and shape then when need to remove them. I know what needs to be done but I don't knowthe proper syntax.

Submitted via EggHeadCafe - Software Developer Portal of Choice
Silverlight Binary Serialization and Compression with WCF Serviceshttp://www.eggheadcafe.com/tutorials/aspnet/96487d4c-d92f-4ca5-85b7-0...

Hi,

Adding a panel control at runtime is not much different adding other
controls in System.Windows.Controls.

An example:

Dim mypanel As New Panel
mypanel.Location = New Point(50, 50)
mypanel.Name = "mypanel_new"
' Let us see borders of panel
mypanel.BorderStyle = BorderStyle.FixedSingle
' Apply additional properties here
' ..............
' Optionally add existing controls to the panel
' e.g: existing button1 on the form
mypanel.Controls.Add(Button1)
' Add panel at the end
Me.Controls.Add(mypanel),


HTH,

Onur Güzel
 
And removing

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
For i = Controls.Count - 1 To 0 Step -1
If Controls(i).Name = "Panel1" Then
Controls.Remove(Controls(i))
Exit For
End If
Next
End Sub

Success

Cor
 
Back
Top