|
-
Jan 1st, 2006, 09:43 PM
#2
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:
Dim MyRemoveList As New ArrayList 'list to hold the controls that need to be removed
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is PictureBox Then
If ctrl.Name <> "pbPreview1" Or ctrl.Name <> "pbPrevTes" Then
MyRemoveList.Add(ctrl) 'adds the control to the list
End If
End If
Next
For Each ctrl As Control In MyRemoveList
Me.Controls.Remove(ctrl) 'removes all of the controls in the list from the form
Next
'and the above should replace your code below...
Dim i As Integer = 0
removeanother:
For i = 0 To Me.Controls.Count - 1
If Me.Controls(i).GetType.ToString = "System.Windows.Forms.PictureBox" Then
If Me.Controls(i).Name <> "pbPreview1" Then
If Me.Controls(i).Name <> "pbPrevTes" Then
Dim oControl As PictureBox
oControl = CType(Me.Controls(i), PictureBox)
oControl.Image = Nothing
Me.Controls.Remove(oControl)
GoTo removeanother
End If
End If
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|