diff --git a/CustomComponents/DropList.Designer.cs b/CustomComponents/DropList.Designer.cs index 4bfc0d7..faa2145 100644 --- a/CustomComponents/DropList.Designer.cs +++ b/CustomComponents/DropList.Designer.cs @@ -39,6 +39,7 @@ listBox.Name = "listBox"; listBox.Size = new Size(150, 104); listBox.TabIndex = 0; + listBox.SelectedValueChanged += // // Frame // diff --git a/CustomComponents/DropList.cs b/CustomComponents/DropList.cs index 811ca50..35ce0eb 100644 --- a/CustomComponents/DropList.cs +++ b/CustomComponents/DropList.cs @@ -3,7 +3,22 @@ public partial class Frame : UserControl { + private event EventHandler? _valueChanged; + private string? SelectedValue = string.Empty; + + public event EventHandler ValueChanged + { + add + { + _valueChanged += value; + } + remove + { + _valueChanged -= value; + } + } + public Frame() { InitializeComponent(); @@ -21,7 +36,6 @@ public void Clear() { listBox.Items.Clear(); - } public string? Value @@ -36,9 +50,11 @@ } } - private void ValueChanged(object sender, EventArgs e) + private void SelectedValue_Changed(object sender, EventArgs e) { - Value = listBox.SelectedItem.ToString(); + var element = sender as ListBox; + Value = element.Text.ToString(); + _valueChanged?.Invoke(this, e); } } } \ No newline at end of file diff --git a/TestForms/Form1.cs b/TestForms/Form1.cs index 3b34758..f25e377 100644 --- a/TestForms/Form1.cs +++ b/TestForms/Form1.cs @@ -2,9 +2,11 @@ namespace TestForms { public partial class TestFrame : Form { + public TestFrame() { InitializeComponent(); + listBox.ValueChanged += new EventHandler() } private void clearButton_Click(object sender, EventArgs e) @@ -15,7 +17,10 @@ namespace TestForms private void fillButton_Click(object sender, EventArgs e) { listBox.PopulateList(new List { "SILENT", "RIZZ", "BLSSDY", "YUEEJKE" }); + } + + } } \ No newline at end of file