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
VulpesPosted May 16, 2013, 5:57 AM
vivaPosted May 16, 2013, 6:34 AM
It is working
VulpesPosted May 16, 2013, 6:29 AM
vivaPosted May 16, 2013, 6:20 AM
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
vivaPosted May 16, 2013, 6:06 AM
this.panel1.Tag = count;
thank u very much
vivaPosted May 16, 2013, 6:04 AM
vivaPosted May 16, 2013, 5:32 AM
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
VulpesPosted May 15, 2013, 9:35 AM