Forums - C# Corner

Forum guidelines


  • 1.4k
  • 27
  • 19.9k

how to pass variable value in event handler

May 15 2013 8:41 AM

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()
            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);

 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


Answers (8)

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!