55 lines
1.2 KiB
C#
55 lines
1.2 KiB
C#
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 VisualComponentsLib.CustomListBox
|
|
{
|
|
[DefaultEvent(nameof(TextChanged))]
|
|
public partial class MyListBox : UserControl
|
|
{
|
|
[Browsable(true)]
|
|
public string selectedString
|
|
{
|
|
get => listBox.SelectedItem.ToString();
|
|
|
|
set
|
|
{
|
|
if (!string.IsNullOrEmpty(value) && listBox.Items.IndexOf(value) != -1)
|
|
{
|
|
listBox.SelectedItem = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public MyListBox()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public event EventHandler? TextChanged
|
|
{
|
|
add => listBox.TextChanged += value;
|
|
remove => listBox.TextChanged -= value;
|
|
}
|
|
|
|
public void addItem(string item)
|
|
{
|
|
if (!string.IsNullOrEmpty(item))
|
|
{
|
|
listBox.Items.Add(item);
|
|
}
|
|
}
|
|
|
|
public void clearAll()
|
|
{
|
|
listBox.Items.Clear();
|
|
}
|
|
}
|
|
}
|