Создал динамические pictureBox, но привязать событие не получается. Что делаю не так не понимаю. Код прилагаю
using OilsGuid.Properties;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace OilsGuid
{
public partial class Home : Form
{
public Home()
{
InitializeComponent();
Load_Menu();
pic6.Click += new EventHandler(this.pic6_Click);
}
private void Load_Menu()
{
this.panel1.Controls.Add(new PictureBox
{
Anchor = AnchorStyles.None,
Image = Resources.рецепт,
Location = new Point(52, 23),
Name = "pic1",
Size = new Size(166, 150),
SizeMode = PictureBoxSizeMode.Zoom
}) ;
this.panel1.Controls.Add(new Label
{
Anchor = AnchorStyles.None,
Font = new Font("Malgun Gothic", 10.8F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
Location = new Point(90, 178),
Name = "label1",
Size = new Size(91, 28),
TabIndex = 1,
Text = "текст",
TextAlign = ContentAlignment.MiddleCenter
});
this.panel1.Controls.Add(new PictureBox
{
Anchor = AnchorStyles.None,
Image = Resources.применение,
Location = new Point(233, 23),
Name = "pic2",
Size = new Size(166, 150),
SizeMode = PictureBoxSizeMode.Zoom
});
this.panel1.Controls.Add(new Label
{
Anchor = AnchorStyles.None,
Font = new Font("Malgun Gothic", 10.8F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
Location = new Point(251, 178),
Name = "label2",
Size = new Size(130, 56),
TabIndex = 1,
Text = "текст",
TextAlign = ContentAlignment.MiddleCenter
});
this.panel1.Controls.Add(new PictureBox
{
Anchor = AnchorStyles.None,
Image = Resources.два,
Location = new Point(416, 23),
Name = "pic3",
Size = new Size(166, 150),
SizeMode = PictureBoxSizeMode.Zoom
});
this.panel1.Controls.Add(new Label
{
Anchor = AnchorStyles.None,
Font = new Font("Malgun Gothic", 10.8F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
Location = new Point(421, 178),
Name = "label3",
Size = new Size(156, 56),
TabIndex = 1,
Text = "Текст",
TextAlign = ContentAlignment.MiddleCenter
});
this.panel1.Controls.Add(new PictureBox
{
Anchor = AnchorStyles.None,
Image = Resources.один,
Location = new Point(52, 251),
Name = "pic4",
Size = new Size(166, 150),
SizeMode = PictureBoxSizeMode.Zoom
});
this.panel1.Controls.Add(new Label
{
Anchor = AnchorStyles.None,
Font = new Font("Malgun Gothic", 10.8F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
Location = new Point(56, 408),
Name = "label4",
Size = new Size(151, 50),
TabIndex = 1,
Text = "Текст",
TextAlign = ContentAlignment.MiddleCenter
});
this.panel1.Controls.Add(new PictureBox
{
Anchor = AnchorStyles.None,
Image = Resources.избранное,
Location = new Point(233, 251),
Name = "pic5",
Size = new Size(166, 150),
SizeMode = PictureBoxSizeMode.Zoom
});
this.panel1.Controls.Add(new Label
{
Anchor = AnchorStyles.None,
Font = new Font("Malgun Gothic", 10.8F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
Location = new Point(455, 408),
Name = "label5",
Size = new Size(88, 28),
TabIndex = 1,
Text = "Заметки",
TextAlign = ContentAlignment.MiddleCenter
});
this.panel1.Controls.Add(new PictureBox
{
Anchor = AnchorStyles.None,
Image = Resources.заметки,
Location = new Point(416, 251),
Name = "pic6",
Size = new Size(166, 150),
SizeMode = PictureBoxSizeMode.Zoom
} );
this.panel1.Controls.Add(new Label
{
Anchor = AnchorStyles.None,
Font = new Font("Malgun Gothic", 10.8F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
Location = new Point(258, 408),
Name = "label6",
Size = new Size(117, 28),
TabIndex = 1,
Text = "Избранное",
TextAlign = ContentAlignment.MiddleCenter
});
}
private void pic6_Click(object sender, EventArgs e)
{
panel1.Visible = false;
}
}
}
PictureBox
, если только Вы не ожидаете, что событие "привяжется" само, потому что Вы написалиName = "pic6",
, а метод называетсяpic6_Click
. Не привяжется.