private void ReloadItems() { contextMenuStrip1.Items.Clear(); contextMenuStrip1.Items.Add(settingsToolStripMenuItem); contextMenuStrip1.Items.Add(toolStripSeparator2); try { XmlSerializer xs = new XmlSerializer(typeof(ConfigProxyItems)); using (StreamReader rd = new StreamReader("proxy-conf.xml")) { ConfigProxyItems c = xs.Deserialize(rd) as ConfigProxyItems; foreach (ProxyItem item in c.ProxyItems) { if (item.Name != null) { ToolStripMenuItem tsm = new ToolStripMenuItem(item.Name); tsm.Click += (sender, e) => SetProxyUrl(item.ConfigUrl); contextMenuStrip1.Items.Add(tsm); } } } } catch (FileNotFoundException ignored) { } contextMenuStrip1.Items.Add(noProxyToolStripMenuItem); contextMenuStrip1.Items.Add(toolStripSeparator1); contextMenuStrip1.Items.Add(exitToolStripMenuItem1); }
private void SettingsUI_Load(object sender, System.EventArgs e) { try { XmlSerializer xs = new XmlSerializer(typeof(ConfigProxyItems)); using (StreamReader rd = new StreamReader("proxy-conf.xml")) { ConfigProxyItems c = xs.Deserialize(rd) as ConfigProxyItems; foreach (ProxyItem item in c.ProxyItems) { if (item.Name != null) { dataGridView1.Rows.Add(item.Name, item.ConfigUrl); } } } } catch (FileNotFoundException ignored) { } }
private void button2_Click(object sender, System.EventArgs e) { ConfigProxyItems c = new ConfigProxyItems(); c.ProxyItems = new System.Collections.Generic.List <ProxyItem>(); foreach (DataGridViewRow item in dataGridView1.Rows) { ProxyItem proxyItem = new ProxyItem(); proxyItem.Name = item.Cells[0].Value as string; proxyItem.ConfigUrl = item.Cells[1].Value as string; c.ProxyItems.Add(proxyItem); } XmlSerializer xs = new XmlSerializer(typeof(ConfigProxyItems)); using (StreamWriter rd = new StreamWriter("proxy-conf.xml")) { xs.Serialize(rd, c); } Dispose(); form1.UpdateItems(); }