//flex table opened by JP

Click to See Complete Forum and Search --> : Coding for dynamically created controls


rockinup1231
09-26-2009, 12:49 AM
In an application I'm writing, there is an option for the user to import images as tiles, and for each tile, a picture box is created that contains the image they select. The newly created picture box is added and sorted automatically in a table layout panel.

The code looks like this:

Dim xtile As Integer = 0
Dim xtile1 As New PictureBox

ImportTileDialog.ShowDialog()

xtile1.Name = "srctile_" + xtile.ToString
xtile1.Height = 50
xtile1.Width = 50
xtile1.SizeMode = PictureBoxSizeMode.StretchImage
xtile1.ImageLocation = ImportTileDialog.FileName
xtile1.Visible = True
xtile1.Enabled = True
xtile1.BringToFront()
TilePanel.Controls.Add(xtile1)
xtile = xtile + 1

However, what I'd like to do and don't know how to do, is make it so these newly created controls can be clicked, and when they are clicked, make them do "something". I know that with a normal control you can add a click event for it, but since these are being created by the application I don't know how to write code each and every one of the tiles that may or may not be created.

I am using VB.NET, in Visual Basic 2008 Express.

Thanks for any help you guys can offer. :t

rockinup1231
09-26-2009, 02:01 AM
Sorry for the double post, but there's another thing I'd like to know how to do as well that pertains to this.

The "something" that I want to happen is I want it so that if one of these created picture boxes are clicked, the image it displays is displayed in a different picturebox as well. Now, I tried using AddHandler and managed to get code to work this way....but the problem I run into is having it figure out which picture box was just clicked and getting the information from that picture box to the other.