#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    122
    Rep Power
    9

    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?

    Code:
    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
    
            actioncombo3(i).Dispose()
            actiontextbox1(i).Dispose()
            actiontextbox2(i).Dispose()
            actiontextbox3(i).Dispose()
            actionlabel1(i).Dispose()
            actionlabel2(i).Dispose()
            actionlabel3(i).Dispose()
            actionlabel4(i).Dispose()
            actionlabel5(i).Dispose()
            actiontextbox4(i).Dispose()
            actiontextbox5(i).Dispose()
            actionlabel6(i).Dispose()
            actionarray1(i) = Nothing
            actionvalue1(i) = Nothing
            actionvalue2(i) = Nothing
            actionvalue3(i) = Nothing
            actionvalue4(i) = Nothing
            actionvalue5(i) = Nothing
            actionvalue6(i) = Nothing
            actionvalue7(i) = Nothing
            ReLoadProject()
        End Sub

    I hope that wasn't to confusing. Please help
    And thanks ahead of time
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    14
    Rep Power
    0
    You're not doing anything to remove the controls.

    Code:
    ?.Controls.Remove(PanelName)
    Use Controls methods.

IMN logo majestic logo threadwatch logo seochat tools logo