Hey guys,
I am setting up several controls on a form at run time using
and then after setting up its location and text, etc and adding it to the forms controls usingCode:dim lblMessage as label = new label
Now when the form is closed i call a function which disposes of all the controls on the form.Code:me.controls.add(lblMessage)
In this function i am using the code
but for some reason to which i am not aware it is only removing and disposing half of all the controls on the form. If i get rid of the code and message out the name of all the controls on the form then it lists all of them but when trying to delete them, it appears to stop half way through.Code:For Each ctrl as Control in Me.Controls Me.Controls.Remove(ctrl) ctrl.dispose() Next
I have also output a message after the code to remove the controls stating how many controls are left on the form (incase it somehow wasn't actually removing them and just hiding the instead) and the message that is displayed shows that there are indeed several controls remaining. I have racked my brain as to the reasons it is doing this and have gained nothing except for a headache, so can anyone else shed some light on the situation and possible tell me where things are going wrong and what i can possibly do to get this to work properly?
Thank you in advance for any help
![]()




Reply With Quote