Extending a PictureBox class

Posted on 2005-05-11
Last Modified: 2008-03-06

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.

Question by:quiTech
    LVL 85

    Accepted Solution

    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

    Author Comment

    Cool!!!!!!! Works really well!

    Quick follow up question: does "MyBase" refer/point to the base class from which the class was extended?
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    That is correct.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now