namespace ComponentsLab { public partial class ImageLoad : UserControl { private event EventHandler? _avatarChanged; private event Action? _errorOccured; public string Error { get; private set; } public Image Avatar { get { return pictureBoxAvatar.Image; } set { pictureBoxAvatar.Image = value; } } public event EventHandler AvatarChanged { add { _avatarChanged += value; } remove { _avatarChanged -= value; } } public event Action AnErrorOccurred { add { _errorOccured += value; } remove { _errorOccured -= value; } } public ImageLoad() { InitializeComponent(); Error = string.Empty; } private void buttonLoad_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { try { pictureBoxAvatar.Image = Image.FromFile(ofd.FileName); _avatarChanged?.Invoke(this, e); } catch (Exception ex) { Error = ex.Message; _errorOccured?.Invoke(); } } } } }