public static Type Show(IWin32Window owner, Type defalt) { using (var dlg = new ListenerChooser()) { dlg.Listener = defalt; return(dlg.ShowDialog(owner) == DialogResult.OK ? dlg.Listener : null); } }
private void m_btnAddListener_Click(object sender, EventArgs e) { var t = ListenerChooser.Show(this, null); if (t == null) { return; } t = ListenerTypes.GetValue(t)?.Type; int maxInt = 0; if (m_lvListeners.Items.Count > 0) { maxInt = m_lvListeners.Items.OfType <ListViewItem>().Max(d => d.Text.Length > 9 && int.TryParse(d.Text.Substring(9), out int index) ? index : 0); } var props = (IListener)Activator.CreateInstance(t); props.Name = "Listener_" + (maxInt + 1).ToString(); //There are no properties, so we have to assign a bogus unique name now. The user can change it in the UI. var item = AddListViewItem(props); item.Selected = true; item.Focused = true; }