Hi
I am beginner in C#.
In for loop , I am creating panel control with Image inside (calling 10 images),When I click on image , it should display value of that Image (Image number) using pop up message box. Please suggest code for the same
public Form1()
{
InitializeComponent();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
for (int count = 1; count < 11; count++)
{
this.panel1 = new System.Windows.Forms.Panel();
// panel1
this.panel1.BackgroundImage = Image.FromFile(Application.StartupPath + "\\activecell.jpg");
this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.panel1.Location = new System.Drawing.Point(50, 50);
this.panel1.Name = "panel1" + count;
this.panel1.Size = new System.Drawing.Size(70, 35);
this.panel1.Click += new System.EventHandler(this.panel1_Click);
this.flowLayoutPanel1.Controls.Add(this.panel1);
}
}
private void panel1_Click(object sender, EventArgs e)
{
}
as I can not pass count variable to panel1_Click variable and i want to display count value on message box.
please reply
regards
Viva
Loading

VulpesRank #55 · 29.2K reputationPosted May 16, 2013, 1:57 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 15, 2013, 5:35 AM EDT
viva27 reputationPosted May 16, 2013, 1:32 AM EDT
But I want to pass any variable value declare in public Form1() to that event.How to do that?
suppose there is other for loop inside running and want to pass that value.how to pass integer??
Viva
viva27 reputationPosted May 16, 2013, 2:04 AM EDT
viva27 reputationPosted May 16, 2013, 2:06 AM EDT
this.panel1.Tag = count;
thank u very much
viva27 reputationPosted May 16, 2013, 2:20 AM EDT
Panel p = (Panel)sender;
string number = p.Name.Substring(5);
string tag = p.Tag.ToString();
if (tag<10)
MessageBox.Show("Image " + number + " is active");
else
MessageBox.Show("Image " + number + " is disable");
but for red mark code I am getting error as
operator can not be applied to operands of type string to int
VulpesRank #55 · 29.2K reputationPosted May 16, 2013, 2:29 AM EDT
viva27 reputationPosted May 16, 2013, 2:34 AM EDT
It is working