Hi
First of all, this is my bit of code:
When I enter the area of the PictureBox I get this error:
If I do the following it works without a flaw:
How can I get the first bit of code to work?
First of all, this is my bit of code:
PictureBox p = new PictureBox();
p.Name = "p" + i.ToString();
p.MouseEnter += (s, ex) => { ((Panel)flowLayoutPanel2.Controls[((PictureBox)sender).Parent.Name]).BorderStyle = BorderStyle.FixedSingle; };
p.MouseLeave += (s, ex) => { ((Panel)flowLayoutPanel2.Controls[((PictureBox)sender).Parent.Name]).BorderStyle = BorderStyle.None; };
When I enter the area of the PictureBox I get this error:
Quote
Unable to cast object of type System.Windows.Forms.Button to type System.Windows.Forms.PictureBox.
If I do the following it works without a flaw:
PictureBox p = new PictureBox();
p.Name = "p" + i.ToString();
p.MouseEnter += p_MouseEnter;
p.MouseLeave += p_MouseLeave;
.
.
.
void p_MouseEnter(object sender, EventArgs e)
{
((Panel)flowLayoutPanel2.Controls[((PictureBox)sender).Parent.Name]).BorderStyle = BorderStyle.FixedSingle;
}
void p_MouseLeave(object sender, EventArgs e)
{
((Panel)flowLayoutPanel2.Controls[((PictureBox)sender).Parent.Name]).BorderStyle = BorderStyle.None;
}
How can I get the first bit of code to work?