[size=2][color=Green][/color][/size]
Hi I am trouble shooting a small issue in c#.net 2003 where i am creating picture box array dynamically and assigning the pictures dynamically.
i am doing this in a panel with autoscroll enabled.
so my picture boxes are having the names like picB[1],picB[2],.....
But if i want to use this names in another event i couldn't do as these are the names will be recognized dynamically by compiler but i am reffering these names when writing code.
so finally i couldn't run the application .
can u give me the solution or better alternatives?
Comments
try this:
[code]
[STAThread]
public static void Main()
{
var win = new Form() { ClientSize = new Size(1000, 100)};
var pnl = new Panel()
{
Dock = DockStyle.Fill,
AutoScroll = true,
};
win.Controls.Add(pnl);
for (int i = 0; i < 1000; i++)
{
var pct = new PictureBox()
{
Dock = DockStyle.Left,
Image = new Bitmap(100, 100),
BorderStyle = BorderStyle.FixedSingle,
Name = "PictureBox" + i,
};
pnl.Controls.Add(pct);
pct.BringToFront();
pct.Click +=
delegate
{
// this delegate will retain the reference of the current pct instance
// So any code you write in this delegate will handle each itteration
// of pct seperately from each other.
// You can also make a class that inherits eventargs and adds a property
// that will allow you to pass the current instance of pct to an actual event
// handler that is tapped into from outside your form class or wherever this
// code may reside. Then any handlers you add will just use the referenced
// picturebox.
MessageBox.Show("The name of this control is " + pct.Name);
};
}
win.ShowDialog();
}
[/code]
><//~Psightoplasm`~
I didnt use delegates till now,so after looking ur code i am now concentrating on them.