private void AppendSolution(Solution solution, bool selected) { // 菜单栏 var item = new ToolStripMenuItem(); item.Text = solution.Text; item.Click += new EventHandler(MiSlnItemClick); MuData.DropDownItems.Add(item); _SolutionMItems[solution.Text] = item; if (selected) { if (_SelectedSlnMItem != null) { _SelectedSlnMItem.Checked = false; } _SelectedSlnMItem = item; _SelectedSlnMItem.Checked = true; } // 状态栏 item = new ToolStripMenuItem(); item.Text = solution.Text; item.Click += new EventHandler(TiSlnItemClick); TuSln.DropDownItems.Add(item); _SolutionTItems[solution.Text] = item; if (selected) { if (_SelectedSlnTItem != null) { _SelectedSlnTItem.Checked = false; } _SelectedSlnTItem = item; _SelectedSlnTItem.Checked = true; } }
private void ListSolution() { if (!Directory.Exists(DAT_DIR)) { return; } string name; Solution sln; foreach (var file in Directory.GetFiles(DAT_DIR, string.Format(HOSTS_FILE, "*"))) { name = Path.GetFileName(file); name = name.Substring(6); sln = new Solution { Key = name, Text = name }; _Solutions.Add(sln); AppendSolution(sln, false); } }
public void Init() { NiTray.Icon = Me.Amon.Hosts.Properties.Resources.Icon; TiHide.Checked = Settings.Default.HideMain; KeyPreview = true; _HostsDir = FindHostsDir(); _HostsFile = Path.Combine(_HostsDir, "hosts"); // 记录 LvItem.BackColor = Color.White; _EnabledBackColor = LvItem.BackColor; _EnabledForeColor = LvItem.ForeColor; _DisabledBackColor = Color.FromArgb(238, 238, 238); _DisabledForeColor = Color.LightGray; _DefaultColor = LvItem.ForeColor; _ChangedColor = Color.Green; // 分组 _DefGroup = new Group { Key = "", Text = "<默认>" }; _Groups = new List<Group>(); _Groups.Add(_DefGroup); _GroupItems = new Dictionary<string, ToolStripMenuItem>(); _CreateGroupSep = new ToolStripSeparator(); _CreateGroupItem = new ToolStripMenuItem(); _CreateGroupItem.Text = "创建新组"; _CreateGroupItem.Click += CiCreateGroupClick; // 方案 _Solution = new Solution(); _Solutions = new List<Solution>(); _SolutionMItems = new Dictionary<string, ToolStripMenuItem>(); _SolutionTItems = new Dictionary<string, ToolStripMenuItem>(); ListSolution(); Reload(); }