Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:12:42+00:00 2026-06-15T03:12:42+00:00

I have searched and seen countless samples here in this forum and in other

  • 0

I have searched and seen countless samples here in this forum and in other sites but I’m still stuck with this problem;
I want to add a Click Handler for dynamically created PictureBox-es and pas an argument on it so I know which one of picture boxes was clicked).

Here is my current code:

Public Class frmMbarimAbonimi

Private Sub frmMbarimAbonimi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'FitnessdbDataSet.clients' table. You can move, or remove it, as needed.
    'Me.ClientsTableAdapter.Fill(Me.FitnessdbDataSet.clients)

    '===============
    Dim dt As DataTable = PaPaguar()
    Dim i As Integer = 0

    Dim gr(dt.Rows.Count) As GroupBox
    Dim pp(dt.Rows.Count) As PictureBox
    Dim lb(dt.Rows.Count) As Label


    For Each row As DataRow In dt.Rows

        gr(i) = New GroupBox
        gr(i).Width = 200
        gr(i).Height = 180

        pp(i) = New PictureBox
        pp(i).SizeMode = PictureBoxSizeMode.StretchImage

        lb(i) = New Label



        '-------------------------
        Try
            Using str As Stream = File.OpenRead("C:\Fotot\" + dt.Rows(i).Item("Foto"))
                pp(i).Image = Image.FromStream(str)
            End Using

            lb(i).Text = dt.Rows(i).Item("Emer")

        Catch ex As Exception

            MsgBox("Fotoja nuk mund te ngarkohet, ju lutem realizoheni nje foto tjeter!!!")

        End Try
        '-------------------------
        pp(i).Visible = True
        pp(i).Width = 200
        pp(i).Height = 150

        AddHandler pp(i).Click, AddressOf testini



        gr(i).Controls.Add(pp(i))

        lb(i).Visible = True
        lb(i).Width = 200
        lb(i).Height = 30
        lb(i).Left = pp(i).Left
        lb(i).Top = pp(i).Top + 150
        lb(i).BackColor = Color.WhiteSmoke
        lb(i).BringToFront()
        gr(i).Controls.Add(lb(i))

        flpanel.Controls.Add(gr(i))

        i = i + 1
    Next row
End Sub 
End Class

So I was trying to use AddHandler pp(i).Click, AddressOf testini but obviously this does not allow me to call “testini” with a parameter to identify which picture box was clicked.

Can someone point me in the right direction or give some advice? Greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:12:43+00:00Added an answer on June 15, 2026 at 3:12 am

    You need to add something to your created PictureBox to identify them in the event handler because you can’t change the signature of the click event handler adding a ‘parameter’

    For example, you could set the Name property

    pp(i) = New GroupBox
    pp(i).Name = "PictureBox" + i.ToString
    

    then in the event handler you could recognize your picture box casting the sender object to a picturebox and grabbing the Name property.
    Remember, sender is always the control that triggers the event. In your case is always one of your dinamically created PictureBoxes

    Private Sub testini(sender As Object, e As System.EventArgs) 
         Dim pb As PictureBox = DirectCast(sender, PictureBox)
         Dim pbIdentity As String = pb.Name
         .....
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched through many times but have not seen this before. Probably really
I have searched apple's documentation and other posts on Stack Overflow, but I'm still
I have searched for the problem I am having, but have seen different variations
I have seen other posts on this subject, but this seems different. I am
I have searched Google and Stackoverflow for this question, but I still don't understand
I have searched this topic on google a bit and seen some best practices.
I have searched for a general solution to this but only find answers to
I have searched and searched for this but I think my terminology isn't correct
I am a new programmer and have searched for this answer, but think I
I searched for a similar question, but haven't seen anyone ask this before. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.