2023-09-20 23:39:46 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
2023-10-05 11:23:18 +04:00
|
|
|
|
|
2023-09-20 23:39:46 +04:00
|
|
|
|
public partial class CustomCheckedListBox : UserControl
|
|
|
|
|
{
|
|
|
|
|
public CustomCheckedListBox()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
checkedListBox.Items.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-05 11:23:18 +04:00
|
|
|
|
public CheckedListBox.ObjectCollection Items
|
2023-09-20 23:39:46 +04:00
|
|
|
|
{
|
2023-10-05 11:23:18 +04:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return checkedListBox.Items;
|
|
|
|
|
}
|
2023-09-20 23:39:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Selected
|
|
|
|
|
{
|
|
|
|
|
get
|
2023-10-05 11:23:18 +04:00
|
|
|
|
{
|
|
|
|
|
if (checkedListBox.SelectedItem != null)
|
2023-09-20 23:39:46 +04:00
|
|
|
|
{
|
2023-10-05 11:23:18 +04:00
|
|
|
|
return checkedListBox.SelectedItem.ToString();
|
2023-09-20 23:39:46 +04:00
|
|
|
|
}
|
2023-10-05 11:23:18 +04:00
|
|
|
|
else
|
2023-09-20 23:39:46 +04:00
|
|
|
|
{
|
2023-10-05 11:23:18 +04:00
|
|
|
|
return "";
|
2023-09-20 23:39:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2023-10-05 11:23:18 +04:00
|
|
|
|
for (int i = 0; i < checkedListBox.Items.Count; ++i)
|
2023-09-20 23:39:46 +04:00
|
|
|
|
{
|
2023-10-05 11:23:18 +04:00
|
|
|
|
if (checkedListBox.Items[i].ToString() == value)
|
|
|
|
|
{
|
|
|
|
|
checkedListBox.SetItemChecked(i, true);
|
|
|
|
|
}
|
2023-09-20 23:39:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|