예제 #1
0
        private void ConnectBtn_Click(object sender, RoutedEventArgs e)
        {
            // Validate the user information.
            int err = 0;
            if (!(Chat.Net.IsPrivateAddress(ServerNameInputBox.Text)))
            {
                err += 1;

                ServerNameInputBox.Text = "Invalid IP Address.";
                ServerNameInputBox.Select(0, ServerPortInputBox.Text.Length);
            }

            int PortNumber;
            try
            {
                PortNumber = int.Parse(ServerPortInputBox.Text);
                if (!(Chat.Net.IsValidPortNumber(PortNumber)))
                {
                    err += 1;
                    ServerPortInputBox.Text = "Invalid Port Number.";
                    ServerNameInputBox.Select(0, ServerPortInputBox.Text.Length);
                }
            }
            catch (Exception)
            {
                err += 1;
                ServerPortInputBox.Text = "Invalid Port Number.";
                ServerNameInputBox.Select(0, ServerPortInputBox.Text.Length);
            }

            // The user properly entered in the IP and the port number and thus we can pass the information to the main form
            if (err == 0)
            {
                UserInfo.ip_address = ServerNameInputBox.Text;   // IP address
                UserInfo.port_number = int.Parse(ServerPortInputBox.Text);  // Port Number
                UserInfo.password = ServerPasswordInputBox.Text; // the password to the server

                // Chat.Client client = new Chat.Client(UserInfo);

                ConnectionFormEventArgs info = new ConnectionFormEventArgs(UserInfo);
                RaiseConnectionFormEvent(this, info);
                this.Close();
            }
        }
예제 #2
0
 // handles the passage of data between forms
 void ConnectDiaglogForm_RaiseCustomEvent(object sender, ConnectionFormEventArgs e)
 {
     UserSettings = e.ServerRequestSettings;
     TryConnection = true;
 }