+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Senior Member rockinup1231's Avatar
    Join Date
    May 2006
    Location
    Northern Michigan
    Posts
    900

    Coding for dynamically created controls

    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:

    Code:
            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.
    MSI 870S-G46 | AMD Phenom II X4 965 @ 3.4ghz | Gigabyte Radeon 7870 Ghz Edition | 2 x WD 500GB Blue HDD | Windows 7 Professional x64 | BFG Tech LS SERIES LS-550 550W | 2 x 4GB DDR3 1600 RAM

  2. #2
    Senior Member rockinup1231's Avatar
    Join Date
    May 2006
    Location
    Northern Michigan
    Posts
    900
    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.
    MSI 870S-G46 | AMD Phenom II X4 965 @ 3.4ghz | Gigabyte Radeon 7870 Ghz Edition | 2 x WD 500GB Blue HDD | Windows 7 Professional x64 | BFG Tech LS SERIES LS-550 550W | 2 x 4GB DDR3 1600 RAM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts







New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q
VMware Updates Hyperic System Management
File Monitoring Key to Enterprise Security
LinkedIn Snaps Up SaaS Player mSpoke