예제 #1
0
        private void Confirm_Click(object sender, EventArgs e)        //确定
        {
            string ipAdrress = IPAddress.Text.Trim();
            string port      = Port.Text.Trim();

            if (ipAdrress == "")
            {
                errormessage.IsBalloon = true;
                errormessage.SetToolTip(this.IPAddress, "地址栏不得为空");
                errormessage.Show("地址栏不得为空", this.IPAddress, 1, this.IPAddress.Height / 2, 2000);
                errormessage.UseFading = false;
                IPAddress.Focus();
                return;
            }
            else if (port == "")
            {
                errormessage.IsBalloon = true;
                errormessage.SetToolTip(this.Port, "端口栏不得为空");
                errormessage.Show("端口栏不得为空", this.Port, 1, this.Port.Height / 2, 2000);
                errormessage.UseFading = false;
                Port.Focus();
                return;
            }
            else
            {
                //将写入的值更新到配置文件中
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings["ipAddress"].Value = ipAdrress;
                config.AppSettings.Settings["port"].Value      = port;
                config.Save();
                ConfigurationManager.RefreshSection("appSettings");

                this.Close();
            }
        }