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. C#
  4. Finding which control triggered an event

Finding which control triggered an event

Scheduled Pinned Locked Moved C#
questioncsharpwinformshelp
5 Posts 3 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.
  • L Offline
    L Offline
    la01
    wrote on last edited by
    #1

    Hi all, This is more of a winforms question. Here's the problem.. I have a FlowLayoutPanel which is populated by several PictureBoxes. Say I click on one of the picture boxes, is there a way I could find out which picture box out of the collection was clicked? Have already considered assigning an ID for each picturebox, but this just seems crude. Is there a sleek way of doing this? Thanks.

    M D 2 Replies Last reply
    0
    • L la01

      Hi all, This is more of a winforms question. Here's the problem.. I have a FlowLayoutPanel which is populated by several PictureBoxes. Say I click on one of the picture boxes, is there a way I could find out which picture box out of the collection was clicked? Have already considered assigning an ID for each picturebox, but this just seems crude. Is there a sleek way of doing this? Thanks.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Every event has a sender object, you can interrogate the object to get the control type and the name (ID) of the control.

      DataGridView oDG = (sender as DataGridView);

      linaaz wrote:

      Have already considered assigning an ID for each picturebox, but this just seems crude. Is there a sleek way of doing this?

      If the name property is not good enough what would you expect to use.

      Never underestimate the power of human stupidity RAH

      L 1 Reply Last reply
      0
      • L la01

        Hi all, This is more of a winforms question. Here's the problem.. I have a FlowLayoutPanel which is populated by several PictureBoxes. Say I click on one of the picture boxes, is there a way I could find out which picture box out of the collection was clicked? Have already considered assigning an ID for each picturebox, but this just seems crude. Is there a sleek way of doing this? Thanks.

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        linaaz wrote:

        considered assigning an ID for each picturebox, but this just seems crude

        Subclassing and adding an ID property is as good as anything else

        public class IdPictureBox : PictureBox
        {
        private int id;

        public int ID
        {
            get { return id; }
            set { id = value; }
        }
        

        }

        Dave
        Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        L 1 Reply Last reply
        0
        • D DaveyM69

          linaaz wrote:

          considered assigning an ID for each picturebox, but this just seems crude

          Subclassing and adding an ID property is as good as anything else

          public class IdPictureBox : PictureBox
          {
          private int id;

          public int ID
          {
              get { return id; }
              set { id = value; }
          }
          

          }

          Dave
          Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          L Offline
          L Offline
          la01
          wrote on last edited by
          #4

          Yup, exactly what I've done. Guess I'll stick with that for now. Thanks.

          1 Reply Last reply
          0
          • M Mycroft Holmes

            Every event has a sender object, you can interrogate the object to get the control type and the name (ID) of the control.

            DataGridView oDG = (sender as DataGridView);

            linaaz wrote:

            Have already considered assigning an ID for each picturebox, but this just seems crude. Is there a sleek way of doing this?

            If the name property is not good enough what would you expect to use.

            Never underestimate the power of human stupidity RAH

            L Offline
            L Offline
            la01
            wrote on last edited by
            #5

            Hmm.. the problem with name was that the names were all the same. So each object was of type PictureBox and had the name picturebox1. But I suppose I could assign different names to each picture box when I instantiate them... somewhat the same as having a custom ID property. Thanks.

            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