jusanthermemory Posted May 23, 2006 Posted May 23, 2006 (edited) is there a way to completly remove a picturebox from a form while its running? Im making a game and its drawing pictures and when a button is clicked I need it to completly delete the pictureboxes. im using visual basic .net any help is greatly appreciated. Edited May 23, 2006 by jusanthermemory Quote
Leaders snarfblam Posted May 23, 2006 Leaders Posted May 23, 2006 How are you referencing the PictureBox? If you want to remove it by the name used in the designer, code like this will work fine: 'Substitute the actual control's name for PictureBox1 Me.Controls.Remove(PictureBox1) Or an event handler... Private Sub PictureBox_Click(sender As Object, e As EventArgs) _ Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click Me.Controls.Remove(DirectCast(sender, Control)) End Sub You'll want to call the Dispose method of the control if you are done with it for good. Quote [sIGPIC]e[/sIGPIC]
jusanthermemory Posted May 23, 2006 Author Posted May 23, 2006 (edited) I used the first code you provided. that should be what I need but its still not quite working right. I have this right now. Me.Controls.Remove(ball1) ball1.Dispose() EDIT: didnt quite explain what wasnt working... heh well the image dissapears and looks to have gone away but the boundaries for it are still there. when I move over that spot the collision detection kicks in even though the object is supposedly gone. is there something I need to put into the dispose parenthesis or am I writing it wrong? im not familiar with it Edited May 23, 2006 by jusanthermemory Quote
Arch4ngel Posted May 23, 2006 Posted May 23, 2006 You could also assign "Nothing" to balll. This would ensure that reference to this object would be erased and be ready for garbage collection. but it should work. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Leaders snarfblam Posted May 23, 2006 Leaders Posted May 23, 2006 You may need to detatch event handlers. How you do it depends on how the event handler was attatched in the first place. If you use the Handles clause (or created a handler with the IDE) you need to set the variable to Nothing so VB removes the handler. Ball1 = Nothing If you used AddHandler, use the RemoveHandler keyword like so... 'Substitute appropriate event RemoveHandler Ball1.Click, AddressOf Ball1_Click [/code] Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.