using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Components { public partial class UserControlStringsListBox : UserControl { private event EventHandler? _listChanged; private event Action? _errorOccured; public string Error { get; private set; } public string ListElement { get { return listBoxStrings.SelectedItem?.ToString(); } set { if (listBoxStrings.Items.Contains(value)) { listBoxStrings.SelectedItem = value; } } } public event EventHandler ListChanged { add { _listChanged += value; } remove { _listChanged -= value; } } public event Action AnErrorOccurred { add { _errorOccured += value; } remove { _errorOccured -= value; } } public UserControlStringsListBox() { InitializeComponent(); Error = string.Empty; } public void AddList(List l) { try { listBoxStrings.Items.AddRange(l.ToArray()); } catch (Exception ex) { Error = ex.Message; _errorOccured?.Invoke(); } } public void ClearList() { listBoxStrings.Items.Clear(); } private void listBoxStrings_SelectedValueChanged(object sender, EventArgs e) { _listChanged?.Invoke(sender, e); } } }