Trying to pass user created image.tag to another forms textbox

Posted on 2007-03-28
Last Modified: 2010-04-23

Using VB.Net VS 2003

I am just getting into public subs and how they work. I have some code where a user has created an image on the tab of a form - Form2. I am trying to put an event handler behind the image for when it is clicked so it will pass the Image.Tag value to a textbox on Form13.

Here is what I have thus far:

Dim tabAttImg As New PictureBox
tabAttImg.Image = clsGlobals.Form2.ImageList1.Images(0)
tabAttImg.Name = "pic" & txtName.Text
tabAttImg.Tag = txtName.Text
tabAttImg.Cursor = System.Windows.Forms.Cursors.Hand
tabAttImg.Size = New Size(16, 16)
tabAttImg.Location = New Point(208, 8 + (TabbyCt * 24))

AddHandler tabAttImg.Click, AddressOf ListClickster(ByVal sender As System.Object, ByVal e As System.EventArgs) 'this line does not work the ByVal text is causing an error - says expression required


'this is the code I want put in a click event behind the image created above. How do I do this?
Public Sub ListClickster(ByVal ctrl As Control)

        If clsGlobals.Form13 Is Nothing Then
            clsGlobals.Form13 = New Form13
        End If

        clsGlobals.Form13.lblTarget.Text = "Target Attribute: " & ctrl.Tag

    End Sub
Question by:PBLack
LVL 85

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 18810823
The sub your are "wiring up" with AddHandler has to have the SAME signature as the event being trapped.

So your ListClickster() sub needs to match the PictureBox.Click() event signature.

Also, in the "AddHandler" only the name of the sub goes after the "AddressOf" part...

Something like...

        AddHandler tabAttImg.Click, AddressOf ListClickster

    Public Sub ListClickster(ByVal sender As Object, ByVal e As System.EventArgs)
        If clsGlobals.Form13 Is Nothing Then
            clsGlobals.Form13 = New Form13
        End If

        clsGlobals.Form13.lblTarget.Text = "Target Attribute: " & sender.Tag
    End Sub

Author Comment

ID: 18810929
thank you - still learning and you helped me move up the curve one more notch


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

15 Experts available now in Live!

Get 1:1 Help Now