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; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace WinFormsLibrary { public partial class CustomCheckedListBox : UserControl { public CustomCheckedListBox() { InitializeComponent(); } public void Clear() { checkedListBox.Items.Clear(); } public CheckedListBox.ObjectCollection Items { get { return checkedListBox.Items; } } public string Selected { get { if (checkedListBox.SelectedItem != null) { return checkedListBox.SelectedItem.ToString(); } else { return ""; } } set { for (int i = 0; i < checkedListBox.Items.Count; ++i) { if (checkedListBox.Items[i].ToString() == value) { checkedListBox.SetItemChecked(i, true); } } } } private EventHandler onValueChanged; public event EventHandler ValueChanged { add { onValueChanged += value; } remove { onValueChanged -= value; } } private void checkedListBox_SelectedValueChanged(object sender, EventArgs e) { onValueChanged?.Invoke(sender, e); } } }