private void GetServerConfig() { if (!iniConfig.ExistINIFile(ConfigPath))//不存在 { iniConfig.CreateIniFile(ConfigPath, "127.0.0.1", 11000); this.ServerAddress = IPAddress.Parse("127.0.0.1"); this.ServerPort = 11000; } else { try { this.ServerAddress = IPAddress.Parse(iniConfig.IniReadValue("Server", "IPAddress", ConfigPath)); } catch { if (MessageBox.Show("IP地址格式不正确,请重新输入") == DialogResult.OK) { Setting.ShowForm(); } } try { this.ServerPort = int.Parse(iniConfig.IniReadValue("Server", "Port", ConfigPath)); } catch { if (MessageBox.Show("端口地址格式不正确,请重新输入") == DialogResult.OK) { Setting.ShowForm(); } } } }
private void Button1_Click(object sender, EventArgs e) { try { IPAddress ip = IPAddress.Parse(this.IPAddresstxt.Text); } catch { MessageBox.Show("IP地址格式不正确,请重新输入"); return; } try { int port = int.Parse(this.centerableTextBox1.Text); } catch { MessageBox.Show("端口地址格式不正确,请重新输入"); return; } if (!iniConfig.ExistINIFile(inipath))//不存在 { iniConfig.CreateIniFile(inipath, this.IPAddresstxt.Text, int.Parse(this.centerableTextBox1.Text)); } else { iniConfig.IniWriteValue("Server", "IPAddress", this.IPAddresstxt.Text, inipath); iniConfig.IniWriteValue("Server", "Port", this.centerableTextBox1.Text, inipath); if (MessageBox.Show("配置修改成功,重启生效", "配置", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK) { Close(); } } }