August 9th, 2012, 04:16 PM
Join Date: Jan 2006
Time spent in forums: 1 Day 13 h 57 m 38 sec
Reputation Power: 8
Removing panels Not! controls!
ive found countless examples for removing controls from a form but i need to remove panels from my form... ill try to explain...
when the user pushes the "+" button a panel is created and added to the form. Then various controls, a link to act as a delete button and 2 more panels are created inside of said panel to create the look that I want. So the combination of controls and panels should act as a custom control so to speak but not really. these combination of panels and controls are created inside of a inner scrolling panel and the inner scrolling panel is inside of a outter panel to allow the inner panel to scroll when the up or down button is pushed. When a new panel is created it is incremented down and added to the inner scrolling panel so the user is able to add as many as they want to the form and be able to scroll through them.
i am trying to figure out the delete button. which is the linklable sub below
now my question is why is this not removing the first panel completely instead of disposing of only the resources in said panel?
Private Sub LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Dim i As Integer
Dim x As Integer
i = dellink(num).Tag
x = 1
Dim controlname As String = "Step" & i
Dim objectsToBeFound As System.Windows.Forms.Control() = InnerStepContainer.Controls.Find(controlname, True)
Dim FoundPanel As Panel = DirectCast(objectsToBeFound(0), Panel) ' pick the first and maybe only control found in the array and put maki it a panel object
InnerStepContainer.Controls.RemoveByKey(FoundPanel.Name) 'remove the panel object from the hosting form
FoundPanel.Dispose() ' free any resources occupied by this
actionarray1(i) = Nothing
actionvalue1(i) = Nothing
actionvalue2(i) = Nothing
actionvalue3(i) = Nothing
actionvalue4(i) = Nothing
actionvalue5(i) = Nothing
actionvalue6(i) = Nothing
actionvalue7(i) = Nothing
I hope that wasn't to confusing. Please help
And thanks ahead of time