private void trayContextMenuServersClick(Object sender, EventArgs e) { ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem; int index = trayContextMenuServers.DropDownItems.IndexOf(toolStripMenuItem); Tunnel tunnel = tunnels[index]; tunnel.enable = !tunnel.enable; serversCheckedListBox.SetItemChecked(index, tunnel.enable); toolStripMenuItem.Checked = tunnel.enable; if (tunnel.enable) { tunnel.connect(); } else { tunnel.disconnect(); } }
private void serverDeleteButtonClick(object sender, EventArgs e) { if (serversCheckedListBox.SelectedItem != null) { string item = serversCheckedListBox.SelectedItem.ToString(); int index = serversCheckedListBox.SelectedIndex; if (!"未配置的服务器".Equals(item)) { if (serversCheckedListBox.Items.Count != 1) { if (serversCheckedListBox.SelectedIndex == 0) { serversCheckedListBox.SelectedIndex = 1; } else if (serversCheckedListBox.SelectedIndex == serversCheckedListBox.Items.Count - 1) { serversCheckedListBox.SelectedIndex = index - 1; } else { serversCheckedListBox.SelectedIndex = index + 1; } } serversCheckedListBox.Items.RemoveAt(index); trayContextMenuServers.DropDownItems.RemoveAt(index); Tunnel tunnel = tunnels[index]; if (tunnel.enable) { tunnel.disconnect(); } tunnels.RemoveAt(index); Utils.writeTunnels(tunnels); } else { serversCheckedListBox.SelectedIndex = index - 1; serversCheckedListBox.Items.RemoveAt(index); } } }