using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace NetTunnelApp { internal class NetCardMenuItems { private static string _selItems = ""; private List _menuItems = new List(); public NetCardMenuItems(List netCardArray) { if (_menuItems.Count > 0) { _menuItems.Clear(); } if (_selItems.Length == 0) { _selItems = netCardArray[0].UUID; } foreach (var netCard in netCardArray) { IPNetwork ipnetwork = IPNetwork.Parse(netCard.IpAddr, netCard.NetMask); ToolStripMenuItem item = new ToolStripMenuItem(); item.Text = netCard.Name + "-[" + netCard.MacAddr + "] " + ipnetwork.Network + "/" + ipnetwork.Cidr; item.Name = netCard.UUID; item.Click += delegate(object sender, EventArgs e) { var control = (ToolStripMenuItem)sender; _selItems = control.Name; foreach (var v in _menuItems) { v.Checked = (_selItems == v.Name); } }; item.Checked = (_selItems == netCard.UUID); if (netCard.Description == "WireGuard Tunnel") { item.Enabled = false; } _menuItems.Add(item); } } public List GetMenuItems() { return _menuItems; } } }