Results 1 to 11 of 11

Thread: {Resolved} - Killing images ... file disposal - access probs?

Threaded View

  1. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Killing images ... file disposal - access probs?

    Well I don't like how you are using the goto statements, and not sure if that is even removing everything it should, try something like this:
    VB Code:
    1. Dim MyRemoveList As New ArrayList 'list to hold the controls that need to be removed
    2.         For Each ctrl As Control In Me.Controls
    3.             If TypeOf ctrl Is PictureBox Then
    4.                 If ctrl.Name <> "pbPreview1" Or ctrl.Name <> "pbPrevTes" Then
    5.                     MyRemoveList.Add(ctrl) 'adds the control to the list
    6.                 End If
    7.             End If
    8.         Next
    9.         For Each ctrl As Control In MyRemoveList
    10.             Me.Controls.Remove(ctrl) 'removes all of the controls in the list from the form
    11.         Next
    12.  
    13. 'and the above should replace your code below...
    14. Dim i As Integer = 0
    15. removeanother:
    16.             For i = 0 To Me.Controls.Count - 1
    17.                 If Me.Controls(i).GetType.ToString = "System.Windows.Forms.PictureBox" Then
    18.                     If Me.Controls(i).Name <> "pbPreview1" Then
    19.                         If Me.Controls(i).Name <> "pbPrevTes" Then
    20.                             Dim oControl As PictureBox
    21.                             oControl = CType(Me.Controls(i), PictureBox)
    22.                             oControl.Image = Nothing
    23.                             Me.Controls.Remove(oControl)
    24.                             GoTo removeanother
    25.                         End If
    26.                     End If
    27.                 End If
    28.             Next i
    I think you were having the same problem I was in testing it when removing a control, it messes up the remove loop because all the control indexes change, which is why I think you did the goto, in order to do it again for all the controls it missed. So the above code makes a list of controls from the controls that need to be removed, then removes them after the list is made...

    Not sure if this will effect anything in the program, but it could if your controls actually arent being removed like they should be.

    I also dont like the Kill command... you should not have to use it at all...
    Last edited by gigemboy; Jan 1st, 2006 at 09:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width