public void creatMain() { MainForm = new Form1(this); MainForm.Show(); MainForm.usernameLabel.Text = this.username; this.Hide(); newChat = new chatbox(this, 0); }
private void button1_Click(object sender, EventArgs e) { if (usernameTextBox.Text != "" && passwordTextBox.Text != "") { if (usernameTextBox.Text == passwordTextBox.Text) { /*Form1 MainForm = new Form1(this); * MainForm.Show(); * this.Hide(); */ //make a connection to server PORT = Int32.Parse("9000"); string myHostname = Dns.GetHostName(); string myIP = Dns.GetHostByName(myHostname).AddressList[0].ToString(); IP = myIP; clientSocket.Connect(IP, PORT); stream = clientSocket.GetStream(); //TcpClient tcpClient = new TcpClient(IP, PORT); //message = "Connected to Chat Server"; //DisplayText(message); if (clientSocket.Connected) { MessageBox.Show("Connected to Server"); MainForm = new Form1(this); MainForm.Show(); this.Hide(); newChat = new chatbox(this); //defining the username byte[] buffer = Encoding.Unicode.GetBytes("Anis" + "$"); stream.Write(buffer, 0, buffer.Length); stream.Flush(); Thread t_handler = new Thread(GetMessage); t_handler.IsBackground = true; t_handler.Start(); } } else { MessageBox.Show("Wrong username or password!"); } } else { MessageBox.Show("Enter your username and password!"); } }