I need to display the picturebox that is formed in the main form in the usercontrol, but also save subscriptions to this picturebox. In this class, I fill in the fields and then use foreach to pass the picturebox to the usercontrol
public class UserCtr
{
public event Action<List<Users>> ClickPicture;
public event Action<List<Users>, Group> DoubleClickPicture;
public Group group { get; set; }
public PictureBox picture { get; set; }
public List<Users> users { get; set; }
public UserCtr(Group group, PictureBox picture, List<Users> users)
{
this.group = group;
this.picture = picture;
this.users = users;
this.picture.Click += PictureClick;
this.picture.MouseDoubleClick += PictureDoubleClick;
}
private void PictureClick(object s, EventArgs e)
{
ClickPicture(users);
}
private void PictureDoubleClick(object s, EventArgs e)
{
DoubleClickPicture(users, group);
}
}
foreach loop
foreach (var item in groups.users)
{
item.picture.Image = yellow;
panel.Controls.Add(new UserControl1(item.picture)
{
Text = item.user.Name,
//pb = item.picture
});
}
My usercontrol
public partial class UserControl1 : UserControl
{
public UserControl1(PictureBox pic)
{
InitializeComponent();
Load += (s, e) => pictureBox1 = pic;
Invalidate();
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
label1.Text = Text;
}
}
}
The label is filled in, and the picturebox is empty