private void toolStripButton5_Click(object sender, EventArgs e) { listView1.Items.Clear(); foreach (Host host in HostsParse.ParseList()) { ListViewItem listViewItem = new ListViewItem(new string[] { host.IP, host.Domain }); listViewItem.Tag = host; listView1.Items.Add(listViewItem); } }
private void MainForm_Load(object sender, EventArgs e) { if (!HostsParse.HostsExists()) { MessageBox.Show("系统hosts文件不存在!", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } foreach (Host host in HostsParse.ParseList()) { ListViewItem listViewItem = new ListViewItem(new string[] { host.IP, host.Domain }); listViewItem.Tag = host; listView1.Items.Add(listViewItem); } }
private void toolStripButton4_Click(object sender, EventArgs e) { try { List <Host> hosts = new List <Host>(); foreach (ListViewItem listViewItem in listView1.Items) { hosts.Add((Host)listViewItem.Tag); } string hosts_string = HostsParse.ListToString(hosts); HostsParse.ReWrite(hosts_string); } catch (UnauthorizedAccessException exception) { MessageBox.Show(exception.Message + "\r\n请以管理员的身份运行程序!", "UnauthorizedAccessException", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exception) { MessageBox.Show(exception.Message, "exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } }