Worms4Editor/W4Gui/Components/CollectiveListAddDelete.cs

77 lines
1.9 KiB
C#

using LibW4M.Data;
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 W4Gui.Components
{
public partial class CollectiveListAddDelete : UserControl
{
public event EventHandler<EventArgs> NewButton;
public event EventHandler<EventArgs> DeleteButton;
public CollectiveListAddDelete()
{
InitializeComponent();
this.List.Unselected += List_Unselected; ;
this.List.Selected += List_Selected; ;
}
protected virtual void OnUnselected(EventArgs e)
{
btnDel.Enabled = false;
}
protected virtual void OnSelected(EventArgs e)
{
btnDel.Enabled = true;
}
protected virtual void OnNewButton(EventArgs e)
{
EventHandler<EventArgs> handler = NewButton;
if (handler != null)
{
handler(this, e);
}
}
protected virtual void OnDeleteButton(EventArgs e)
{
EventHandler<EventArgs> handler = DeleteButton;
if (handler != null)
{
handler(this, e);
if (this.List.Items.Count <= 0)
this.btnDel.Enabled = false;
}
}
private void List_Selected(object? sender, EventArgs e)
{
OnSelected(e);
}
private void List_Unselected(object? sender, EventArgs e)
{
OnUnselected(e);
}
private void btnAdd_Click(object? sender, EventArgs e)
{
OnNewButton(e);
}
private void btnDel_Click(object? sender, EventArgs e)
{
if (this.List.SelectedIndex >= 0)
OnDeleteButton(e);
}
}
}