private void OKButton_Click(object sender, RoutedEventArgs e) { scanstarttext = ScanIPStarttextBox_1.Text + "." + ScanIPStarttextBox_2.Text + "." + ScanIPStarttextBox_3.Text + "." + ScanIPStarttextBox_4.Text; scanendtext = ScanIPEndtextBox_1.Text + "." + ScanIPEndtextBox_2.Text + "." + ScanIPEndtextBox_3.Text + "." + ScanIPEndtextBox_4.Text; IPAddress ip; if (IPAddress.TryParse(scanstarttext, out ip) && IPAddress.TryParse(scanendtext, out ip)) { if ((Convert.ToInt16(ScanIPStarttextBox_1.Text) == Convert.ToInt16(ScanIPEndtextBox_1.Text)) && (Convert.ToInt16(ScanIPStarttextBox_2.Text) == Convert.ToInt16(ScanIPEndtextBox_2.Text)) && (Convert.ToInt16(ScanIPStarttextBox_3.Text) == Convert.ToInt16(ScanIPEndtextBox_3.Text)) && (Convert.ToInt16(ScanIPStarttextBox_4.Text) <= Convert.ToInt16(ScanIPEndtextBox_4.Text))) { //将设备扫描范围存入配置文件 XmlSerializationHelper configContext = new XmlSerializationHelper("Config"); GlobalConfig globalconfig = configContext.Get <GlobalConfig>(); string Awarry = globalconfig.ScanIPConfig[0].scanip; globalconfig.ScanIPConfig[0].scanip = Awarry + "+" + scanstarttext + "-" + scanendtext; configContext.Save(globalconfig); StaticGlobal.ScanIP = globalconfig.ScanIPConfig[0].scanip; this.Close(); } else { UserMessageBox.Show("提示", "请输入正确的范围!"); } } else { UserMessageBox.Show("提示", "请输入正确的IP!"); } }