Extending a PictureBox class


I would like to create a new class, extending the PicutreBox class, adding a few extra "bits".  Specifically, the bits are:

- an extra text property called "ID" (or someting similar if ID is reserved)
- a generic "onmouseover" event that is fired each time the mouse enters on of these picture boxes, passing the ID value to the event handling sub.

The goal is to be able to create an arbitrary number of these picture boxes at runtime, each with a unique ID, then do something based on the ID, if the user moves the mouse over one of these picture boxes.

Hope 500 points is enough for this... would give more, but 500 seems to be the limit.

Who is Participating?
Mike TomlinsonMiddle School Assistant TeacherCommented:
Something like...

Public Class PictureBoxID
    Inherits System.Windows.Forms.PictureBox

    Private strID As String
    Private Shared IDs As New Hashtable

    Public Event MouseEnterID(ByVal ID As String)

    Public Property ID() As String
            Return strID
        End Get
        Set(ByVal Value As String)
            If Not IDs.ContainsKey(Value) Then
                If strID <> "" Then
                    If IDs.ContainsKey(strID) Then
                    End If
                End If
                strID = Value
                IDs.Add(strID, Nothing)
                    MessageBox.Show(Value, "Duplicate Key", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
        End Set
    End Property

    Private Sub PictureBoxID_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseEnter
        RaiseEvent MouseEnterID(strID)
    End Sub

    Protected Overrides Sub Finalize()
        If strID <> "" AndAlso IDs.ContainsKey(strID) Then
        End If

    End Sub

End Class
quiTechAuthor Commented:
Cool!!!!!!! Works really well!

Quick follow up question: does "MyBase" refer/point to the base class from which the class was extended?
Mike TomlinsonMiddle School Assistant TeacherCommented:
That is correct.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.