2023-09-13 11:54:50 +04:00

51 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 UserListBox : UserControl
{
[Browsable(true)]
public string selectedString
{
get => listBox.SelectedItem.ToString();
set => listBox.SelectedItem = value;
}
public UserListBox()
{
InitializeComponent();
}
[Browsable(true)]
public new event EventHandler? TextChanged
{
add => listBox.Items.Add(value);
remove => listBox.Items.Clear();
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox.Text))
{
listBox.Items.Add(textBox.Text);
textBox.Text = string.Empty;
}
}
private void ButtonRemove_Click(object sender, EventArgs e)
{
listBox.Items.Clear();
}
}
}