Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by jusanthermemory
  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted (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 by jusanthermemory
Posted

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.

"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
Posted

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]

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...