Hello my fellow Daniwebbers, I have a modest question for you.


I have a panel, which contains child panels.

I have code the alows the user to delete the selected panel, but can't figure out how to refresh the parent panel with the deleted panel gone. When I use the refresh, the empty space is still there... So, I wrote a block of code that is supposed to "shift" all of the panels up to the deleted panels position. But when the code is executed, the panel to delete is deleted...along with everything above it. :S

Here is my code.

'Allows the user to delete the currently selected tab on the tab control.
        Try
            If Not (selectedPanel Is Nothing) And Not (myPanels Is Nothing) Then
                For i = 0 To myPanels.Count - 1
                    If myPanels(i).pnl Is selectedPanel Then
                        For j = i + 1 To myPanels.Count - 1
                            If j <> myPanels.Count Then
                                myPanels(j).loc = myPanels(i).loc
                                myPanels(i).pnl = myPanels(j).pnl
                                j += 1
                            End If
                        Next
                        selectedPanel.Dispose()
                        ImagePanel.Controls.Clear()
                        ImagePanel.Refresh()
                    End If
                Next
                For i = 0 To myPanels.Count - 1
                    If Not (myPanels(i).pnl Is Nothing) Then
                        ImagePanel.Controls.Add(myPanels(i).pnl)
                    End If
                Next
                Return
            End If
        Catch ex As Exception
            MsgBox("Exception from: " & ex.Source & vbCrLf & ex.Message & vbCrLf & vbCrLf & ex.StackTrace.ToString, MsgBoxStyle.OkOnly)
            Return
        End Try

"Edit..."
More info:

'Declaration of myPanels
dim myPanels(100) as panelArray


'Declaration of panelArray
    Public Structure panelArray
        Public pnl As Panel
        Public loc As System.Drawing.Point
        Public siz As System.Drawing.Size
    End Structure

Edited 4 Years Ago by Begginnerdev: n/a

I have it some what working. Now it shifts up, but it pushes the top panel "off screen"

Here is the code that works for the shift:

'Allows the user to delete the currently selected tab on the tab control.
        Try
            If Not (selectedPanel Is Nothing) And Not (myPanels Is Nothing) Then
                For i = 0 To myPanels.Count - 1
                    If Not (myPanels(i).pnl Is Nothing) Then
                        If myPanels(i).pnl.Name = selectedPanel.Name Then
                            For j = i + 1 To myPanels.Count - 1
                                If j <> myPanels.Count And Not (myPanels(i).pnl Is Nothing) And Not (myPanels(j).pnl Is Nothing) Then
                                    myPanels(j).pnl.Location = myPanels(i).pnl.Location
                                    myPanels(i).pnl = myPanels(j).pnl
                                End If
                            Next
                            ImagePanel.Controls.Clear()
                            ImagePanel.Refresh()
                        End If
                    End If
                Next
                For i = 0 To myPanels.Count - 1
                    If Not (myPanels(i).pnl Is Nothing) Then
                        ImagePanel.Controls.Add(myPanels(i).pnl)
                    End If
                Next
            End If
        Catch ex As Exception
            MsgBox("Exception from: " & ex.Source & vbCrLf & ex.Message & vbCrLf & vbCrLf & ex.StackTrace.ToString, MsgBoxStyle.OkOnly)
            Return
        End Try

Edited 4 Years Ago by Begginnerdev: n/a

Is there any way to pull from the location INSIDE the panel? I think that is my problem. When I am scrolling down to delete the panel, they shift up to the panel above and is set to the size of the panel that I see. So if I am looking at a 1/4 of the panel for the one above, and I delete the one below - The one below is shifted up the location of the first, which makes only 1/4 of it viewable.

Anyone have any suggestions?

Edited 4 Years Ago by Begginnerdev: n/a

Getting closer. Found possible issue? Loop through and push panel values forward?

Edited 4 Years Ago by Begginnerdev: n/a

OK, I have rewritten my code about 9 times now.

Here is what I have now.

'Allows the user to delete the currently selected tab on the tab control.
        Try
            If Not (selectedPanel Is Nothing) And Not (myPanels Is Nothing) Then

                For i = 0 To myPanels.Count - 1
                    If myPanels(i).pnl Is selectedPanel Then
                        myPanels(i).pnl = Nothing
                    End If
                Next

                For i = 0 To myPanels.Count - 1
                    If (i + 1) < myPanels.Count Then
                        If Not (myPanels(i).pnl Is Nothing) And Not (myPanels(i).loc = Nothing) Then
                            tmpPanels(i).loc = myPanels(i).loc
                            tmpPanels(i).pnl = myPanels(i).pnl
                            myPanels(i).loc = Nothing
                            myPanels(i).pnl = Nothing
                        ElseIf myPanels(i).pnl Is Nothing And Not (myPanels(i).loc = Nothing) And Not (myPanels(i + 1).pnl Is Nothing) Then
                            If (i + 1) < myPanels.Count Then
                                tmpPanels(i).loc = myPanels(i).loc
                                tmpPanels(i).pnl = myPanels(i + 1).pnl
                                myPanels(i).loc = Nothing
                            End If
                        ElseIf Not (myPanels(i).loc = Nothing) And myPanels(i + 1).pnl Is Nothing And myPanels(i + 1).loc = Nothing Then
                            myPanels(i).loc = Nothing
                        End If
                    End If
                Next
                ImagePanel.Controls.Clear()

                For x = 0 To myPanels.Count - 1
                    myPanels(x).pnl = Nothing
                    myPanels(x).loc = Nothing
                Next

                For x = 0 To tmpPanels.Count - 1
                    If Not (tmpPanels(x).pnl Is Nothing) And Not (tmpPanels(x).loc = Nothing) Then
                        createPanel(tmpPanels(x).pnl.Name)
                    End If
                Next

            End If
        Catch ex As Exception
            MsgBox("Exception from: " & ex.Source & vbCrLf & ex.Message & vbCrLf & vbCrLf & ex.StackTrace.ToString, MsgBoxStyle.OkOnly)
            Return
        End Try

Basicly what I am trying to do is this.


x = panels _ = drawing location of panel

X X X X X
_ _ _ _ _ Array 1

Array 2 (empty)

if I deleted the value from array 1, I want to shift everything up one drawing location:

X X X X
_ _ _ _ _ Array 1

Array 2 (empty)

X X X X
_ _ _ _ _ Array 1

X X X X
_ _ _ _ _ Array 2

and then delete the orphaned drawing location:


X X X X
_ _ _ _ _ Array 1

X X X X
_ _ _ _ Array 2

But when i start pulling from array 2 to reload the panels, the list comes up fine first delete, after that it starts repeating the panels.

I know, it's crazy! If anyone has any suggestions, it would be greatly appreciated.

Thanks,
BegginnerDev

Edited 4 Years Ago by Begginnerdev: n/a

Solved. All that had to be done is loop through and pull all objects of the panel type, and store them in the arrray. Then post all remain objects back to the empty panel.

Code:

Try
            If IsNothing(selectedPanel) = False And IsNothing(myPanels) = False Then
                Dim i As Integer = 0
                For Each p As Panel In ImagePanel.Controls
                    If p Is selectedPanel Then
                        tmpPanels(i).pnl = Nothing
                        i += 1
                    Else
                        tmpPanels(i).pnl = p
                        i += 1
                    End If
                Next

                ImagePanel.Controls.Clear()

                For z = 0 To tmpPanels.Count - 1
                    If IsNothing(tmpPanels(z).pnl) = False Then
                        createPanel(tmpPanels(z).pnl.Name)
                    End If
                Next
                For j = 0 To tmpPanels.Count - 1
                    tmpPanels(j).pnl = Nothing
                Next
            Else
                MsgBox("Please select a panel to delete.", MsgBoxStyle.OkOnly)
            End If
        Catch ex As Exception
            MsgBox("Exception from: " & ex.Source & vbCrLf & ex.Message & vbCrLf & vbCrLf & ex.StackTrace.ToString, MsgBoxStyle.OkOnly)
            Return
        End Try
This question has already been answered. Start a new discussion instead.