Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Picture Box Array Problem

Picture Box Array Problem

Scheduled Pinned Locked Moved Visual Basic
helpdata-structurestutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    I want to create an array of picture boxes (about 10) through code. I have done this succesfully and have them showing up on the form just fine. I can control the size/color and all of that fine when I create them, but after they are on the screen, I can not click on them and get it to run code. I have used the addhandler to assign a click, but when it runs, I don' know how to tell it which box I clicked on. I want to be able to have the pic box I click on change it's image to a different one. When I do this, it always changes the last box, not the one I click on. I found the arrays don't work as they did in VB 6. Please help :sigh:

    N 1 Reply Last reply
    0
    • A Anonymous

      I want to create an array of picture boxes (about 10) through code. I have done this succesfully and have them showing up on the form just fine. I can control the size/color and all of that fine when I create them, but after they are on the screen, I can not click on them and get it to run code. I have used the addhandler to assign a click, but when it runs, I don' know how to tell it which box I clicked on. I want to be able to have the pic box I click on change it's image to a different one. When I do this, it always changes the last box, not the one I click on. I found the arrays don't work as they did in VB 6. Please help :sigh:

      N Offline
      N Offline
      Nick Seng
      wrote on last edited by
      #2

      Well the event handler of PictureBox click has an object parameter called Sender, which is actually the picturebox object clicked. To do what you want, this is what you do:

      Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
      Dim a As PictureBox = CType(sender, PictureBox)
      a.Image = .....

      HTH


      "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler. Support Bone

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups