ramone Posted October 9, 2005 Posted October 9, 2005 (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 October 9, 2005 by ramone Quote
*Experts* DiverDan Posted October 9, 2005 *Experts* Posted October 9, 2005 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. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
ramone Posted October 9, 2005 Author Posted October 9, 2005 thank you that was very helpful!!! :D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.