4 Replies - 561 Views - Last Post: 05 October 2012 - 03:46 PM Rate Topic: -----

#1 Coolclone  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 24-September 12

Deleting a picturebox that is created while the program is running

Posted 02 October 2012 - 11:18 AM

Howdy! So I've made a program that randomly creates images on a form. What I want is when the mouse enters a picture, that picturebox is deleted. When the picture is made, the value in the name is increased by one for each new picture.
 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim x As Integer = randomGen.Next(0, 732)
        Dim y As Integer = randomGen.Next(0, 440)

        protetNum = protetNum + 1

        Dim picturebox As New PictureBox
        picturebox.Name = "protet" + protetNum.ToString
        picturebox.SizeMode = PictureBoxSizeMode.StretchImage
        picturebox.Image = System.Drawing.Bitmap.FromFile(My.Computer.FileSystem.GetName("jumping alien.gif"))
        picturebox.Location = New Point(x, y)

        Me.Controls.Add(picturebox)

        If protetNum = 100 Then Timer1.Enabled = False
        If protetNum <= 99 Then Timer1.Enabled = True
    End Sub 


That is run everytime a timer ticks. Here is the code so far for when the mouse enters the picturebox.

     Private Sub picturebox_testpicEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
        'This doesn't work.  Don't know how to take the vague picturebox and turn into specifics.
        My.Computer.Audio.Play("Death-01.wav")


    End Sub 


There may be more errors here than I thought, but my knowledge of VB is only so much. If it helps, this stumped my VB teacher as well.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Deleting a picturebox that is created while the program is running

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Deleting a picturebox that is created while the program is running

Posted 02 October 2012 - 11:33 AM

I think you need to add a handler that calls your sub

From there, you should be able to use the sender object and cast it to a picturebox where you can expose the properties specific to it.
Was This Post Helpful? 1
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,273
  • Joined: 12-June 08

Re: Deleting a picturebox that is created while the program is running

Posted 02 October 2012 - 11:36 AM

Have you thought about using the event's "add handler"?

'-- ---------
        Dim foo As New PictureBox
        AddHandler foo.MouseEnter, AddressOf bar_MouseEnter

'-- ---------
    Private Sub bar_MouseEnter(sender As Object, e As System.EventArgs)

    End Sub



http://msdn.microsof...v=vs.80%29.aspx
Was This Post Helpful? 1
  • +
  • -

#4 Coolclone  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 24-September 12

Re: Deleting a picturebox that is created while the program is running

Posted 04 October 2012 - 11:22 AM

Sorry for the late response, but this worked very well. You guys are great, three for three so far!
Was This Post Helpful? 0
  • +
  • -

#5 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 976
  • Joined: 09-May 09

Re: Deleting a picturebox that is created while the program is running

Posted 05 October 2012 - 03:46 PM

ive tried a different method that seems to work for me. create a global array of type picturebox, create your picturebox and assign it to the array. you can easy dispose of the objects from anywhere then

kevin
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1