private void LoadConfig() { if (!File.Exists(Device.fun_normal_configFilePath) || ToolCls.FileIsUsed(Device.fun_normal_configFilePath)) { MessageBox.Show("文件下载中,请稍后再试!"); return; } var core_Content = File.ReadAllText(Device.fun_normal_configFilePath); var aryContent = core_Content.Split('\n'); foreach (var item in aryContent) { if (item.Contains("=")) { var ary_item = item.Split('='); dictConfig.Add(ary_item[0], ary_item[1]); } } foreach (Control item in this.Controls)//赋值给控件 { if (item is TextBox) { var textBox = item as TextBox; var key = textBox.Name.Replace("txt_", ""); if (dictConfig.ContainsKey(key)) { textBox.Text = dictConfig[key]; } } } }
private void LoadConfig() { if (!File.Exists(Device.eth_configFilePath) || ToolCls.FileIsUsed(Device.eth_configFilePath)) { MessageBox.Show("文件下载中,请稍后再试!"); return; } var eth_Content = File.ReadAllText(Device.eth_configFilePath); XmlDocument doc = new XmlDocument(); doc.LoadXml(eth_Content); var eth_el = ToolCls.GetFromXMLEl(doc, "/root/eth"); var dns_el = ToolCls.GetFromXMLEl(doc, "/root/eth/dns"); var ip = eth_el.GetAttribute("ip"); var submask = eth_el.GetAttribute("submask"); var gateway = eth_el.GetAttribute("gateway"); var dns1 = dns_el.GetAttribute("dns1"); var dns2 = dns_el.GetAttribute("dns2"); txtIP.Text = ip; txtsubmask.Text = submask; txtgateway.Text = gateway; txtdns1.Text = dns1; txtdns2.Text = dns2; }