Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Extending a PictureBox class

Posted on 2005-05-11
3
Medium Priority
?
261 Views
Last Modified: 2008-03-06
Hello,

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.

Thanks
0
Comment
Question by:quiTech
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 13982708
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
        Get
            Return strID
        End Get
        Set(ByVal Value As String)
            If Not IDs.ContainsKey(Value) Then
                If strID <> "" Then
                    If IDs.ContainsKey(strID) Then
                        IDs.Remove(strID)
                    End If
                End If
                strID = Value
                IDs.Add(strID, Nothing)
            Else
                    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
            IDs.Remove(strID)
        End If

        MyBase.Finalize()
    End Sub

End Class
0
 

Author Comment

by:quiTech
ID: 13983014
Cool!!!!!!! Works really well!

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

Expert Comment

by:Mike Tomlinson
ID: 13983783
That is correct.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

564 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