Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

hello

i have a loop that creates controls with info from db, this controls are pictureboxes, after being created and configured they are added to a panel control, how can i set event handlers for click and double click events to this controls as they are created??

 

here is my code:

 

Private Sub fotos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim dt As DataTable = selectDatos(Me.cnxStr, "select id_foto,ext from fotos where id_paciente=" + idpacientecur)
       Dim dr As DataRow
       Dim foto As PictureBox

'loop to create pictureboxes
       For Each dr In dt.Rows
           foto = New PictureBox
           foto.Size = New Size(90, 90)
           foto.SizeMode = PictureBoxSizeMode.StretchImage
           foto.Image = Image.FromFile(Me.path + "fotos\" + Me.idpacientecur + "\" + cString(dr.Item(0)) + "." + dr.Item(1))
'add to panel control
           panelFotos.Controls.Add(foto)
           foto.Location = New Point(Me.refx, Me.refy)
           foto.Cursor = Cursors.Hand
           Me.refx = Me.refx + 100
'here i want to add the event handlers for click and double click events
       Next
   End Sub

 

thanks for your help

Edited by ramone
  • *Experts*
Posted

You'll need to create a couple of event handlers for the click and double click events.

 

 

Private Sub Foto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
   'blah
End Sub

Private Sub Foto_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
   'blah
End Sub

Private Sub fotos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim dt As DataTable = selectDatos(Me.cnxStr, "select id_foto,ext from fotos where id_paciente=" + idpacientecur)
       Dim dr As DataRow
       Dim foto As PictureBox

'loop to create pictureboxes
       For Each dr In dt.Rows
           foto = New PictureBox
           foto.Size = New Size(90, 90)
           foto.SizeMode = PictureBoxSizeMode.StretchImage
           foto.Image = Image.FromFile(Me.path + "fotos" + Me.idpacientecur + "" + cString(dr.Item(0)) + "." + dr.Item(1))
'add to panel control
           panelFotos.Controls.Add(foto)
           foto.Location = New Point(Me.refx, Me.refy)
           foto.Cursor = Cursors.Hand
           Me.refx = Me.refx + 100
           AddHandler foto.Click, AddressOf Foto_Click
           AddHandler foto.DoubleClick, AddressOf Foto_DoubleClick
       Next
End Sub 

 

I hope that gives you and idea how to do it.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...