This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
CC-Functions/W32/Forms/SelectBox.cs

30 lines
827 B
C#
Raw Normal View History

namespace CC_Functions.W32.Forms
{
2019-12-22 16:58:16 +01:00
internal partial class SelectBox<T> : Form
{
public T result;
2019-12-22 16:58:16 +01:00
public SelectBox(T[] Options, string title = "")
{
InitializeComponent();
Text = title;
2019-12-22 16:58:16 +01:00
listBox1.Items.AddRange(Options.Select(s => (object) s).ToArray());
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
2019-12-22 16:58:16 +01:00
result = (T) listBox1.SelectedItem;
DialogResult = DialogResult.OK;
Close();
}
}
public static class SelectBox
{
public static T Show<T>(T[] Options, string title = "")
{
SelectBox<T> sb = new SelectBox<T>(Options, title);
2019-12-22 16:58:16 +01:00
return sb.ShowDialog() == DialogResult.OK ? sb.result : default;
}
}
2019-12-22 16:58:16 +01:00
}