MouseHover over ANY picturebox

reece withers
reece withers used Ask the Experts™
on
Hi, I've just finished my game except for this part.

I need to mousehover over any balloon picturebox in my forms to then pop them and animate, but i can do that part myself

I don't know how to make a hover event / function with the way i've approached this

PLEASEE HELP I'M GETTING REALLY DESPERATE :(

Code:

Imports System.Drawing
Imports System.Windows.Forms
Public Class stage1
    Dim holdbox() As PictureBox

    Dim score As Integer = 0

    Private Sub stage1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        tmrSpawn.Start()
        tmrMove.Start()
    End Sub
    Public Sub tmrSpawn_Tick(sender As Object, e As EventArgs) Handles tmrSpawn.Tick
        Dim holdbox(3) As PictureBox
        For i = 1 To 3
            holdbox(i) = New PictureBox
            holdbox(i).Name = "balloon" + Str(i)
            holdbox(i).Image = Image.FromFile("C:\Users\Reece\Desktop\School Work Year 12\VB Projects\PopGame.vb\balloon.png")
            holdbox(i).BackColor = Color.Transparent
            holdbox(i).Location = New Point(((400 - 1 + 1) * Rnd() + 1), 0)
            holdbox(i).Size = New Size(70, 30)
            holdbox(i).Visible = True
            holdbox(i).SizeMode = PictureBoxSizeMode.StretchImage
            Me.Controls.Add(holdbox(i))
        Next
    End Sub

    Private Sub tmrBegin_Tick(sender As Object, e As EventArgs) Handles tmrBegin.Tick
        tmrSpawn.Enabled = True
    End Sub

    Public Sub tmrMove_Tick(sender As Object, e As EventArgs) Handles tmrMove.Tick
        Dim ToLoc As Point
        For Each pic As Control In Me.Controls
            If TypeOf pic Is PictureBox Then
                ToLoc.X = pic.Location.X
                ToLoc.Y = pic.Location.Y + 10
                pic.Location = ToLoc
            End If
        Next
    End Sub

End Class
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
When you dynamically create your instances of PictureBox, you need to "wire up" whatever events you want using "AddHandler":
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/addhandler-statement

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial