public MainForm() { InitializeComponent(); txtCurrentNTPServer.Text = Program.CurrentNTPServerUrl; this.Text = string.Format(title, txtCurrentNTPServer.Text); SNTP = new SNTPClient(Program.CurrentNTPServerUrl); loopThread = new Thread(TimeSync); loopThread.Start(); }
private void btnTimeCheck_Click(object sender, EventArgs e) { if (btnTimeCheck.Tag.ToString() == "Modify") { txtCurrentNTPServer.ReadOnly = false; btnTimeCheck.Text = "确定"; btnTimeCheck.Tag = "OK"; } else if (btnTimeCheck.Tag.ToString() == "OK") { if (string.IsNullOrEmpty(txtCurrentNTPServer.Text)) { MessageBox.Show("NTP服务器的地址不能为空"); return; } Program.CurrentNTPServerUrl = txtCurrentNTPServer.Text; txtCurrentNTPServer.ReadOnly = true; btnTimeCheck.Tag = "Modify"; btnTimeCheck.Text = "修改"; bool isModified = false; foreach (string key in ConfigurationManager.AppSettings) { if (key == "CurrentNTPServerUrl") { isModified = true; } } Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (isModified) { config.AppSettings.Settings.Remove("CurrentNTPServerUrl"); } config.AppSettings.Settings.Add("CurrentNTPServerUrl", txtCurrentNTPServer.Text); config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); SNTP = new SNTPClient(Program.CurrentNTPServerUrl); this.Text = string.Format(title, txtCurrentNTPServer.Text); } }