Forums - C# Corner

Forum guidelines
viva

viva

  • 1.3k
  • 27
  • 18.6k

how to pass variable value in event handler

May 15 2013 8:41 AM
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

Answers (8)

Download Free eBooks

SPONSORED BY

File APIs for .NET
Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!