Esempio n. 1
0
        private void SaveConfig(object sender, RoutedEventArgs e)
        {
            bool error = false;

            try
            {
                int portIn = Convert.ToInt32(TextBoxPortIn.Text);

                if (portIn >= 1 && portIn <= 65535)
                {
                    client.PortReceive = portIn;
                }
                else
                {
                    throw new ArgumentException("Invalid UDP port number");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please enter a valid port number between 1-65535.");
                TextBoxPortIn.Focus();
                error = true;
            }

            try
            {
                int portOut = Convert.ToInt32(TextBoxPortOut.Text);

                if (portOut >= 1 && portOut <= 65535)
                {
                    client.PortSend = portOut;
                }
                else
                {
                    throw new ArgumentException("Invalid TCP/IP port number");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please enter a valid port number between 1-65535.");
                TextBoxPortOut.Focus();
                error = true;
            }

            try
            {
                IPAddress ipAdd = IPAddress.Parse(TextBoxIPAddress.Text);
                client.IPAddress = ipAdd;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please enter a valid IP address such as 127.0.0.1");
                TextBoxIPAddress.Focus();
                error = true;
            }

            if (!error)
            {
                client.Settings.WriteConfigFile();
                GridConfig.Visibility = Visibility.Collapsed;
            }
        }
 private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
 {
     // Need to be in loaded event, focusmanger won't work...
     TextBoxIPAddress.Focus();
 }