Finding which control triggered an event
-
Hi all, This is more of a winforms question. Here's the problem.. I have a
FlowLayoutPanel
which is populated by severalPictureBox
es. 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. -
Hi all, This is more of a winforms question. Here's the problem.. I have a
FlowLayoutPanel
which is populated by severalPictureBox
es. 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.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
-
Hi all, This is more of a winforms question. Here's the problem.. I have a
FlowLayoutPanel
which is populated by severalPictureBox
es. 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.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) -
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) -
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
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.