private void button1_Click(object sender, EventArgs e) { if (txtNickname.Text == "") { MessageBox.Show("Nick name is empty"); } else { ClientChat client = new ClientChat(txtNickname.Text); client.FormClosed += Client_FormClosed; this.Hide(); client.Show(); } }
public void Client_Received(ClientChat client, string receivedMsg) { var cmd = receivedMsg.Split('|'); switch (cmd[0]) { case "Users": this.Invoke(() => { userList.Items.Clear(); for (int i = 1; i < cmd.Length; i++) { if (cmd[i] != "Connected" | cmd[i] != "RefreshChat") { userList.Items.Add(cmd[i]); } } } ); break; case "Message": this.Invoke(() => { txtReceivedMsg.Text += cmd[1] + "\r\n"; }); break; case "RefreshChat": this.Invoke(() => { txtReceivedMsg.Text = cmd[1]; }); break; case "Chat": this.Invoke(() => { pChat.Text = pChat.Text.Replace("user", main.txtUsername.Text); pChat.Show(); }); break; case "pMessage": this.Invoke(() => { pChat.txtReceivedMsg.Text += "Server: " + cmd[1] + "\r\n"; }); break; case "Disconnect": Application.Exit(); break; } }
public MainForm() { client = new ClientChat(); InitializeComponent(); }
private static void Client_Disconnected(ClientChat clientChat) { }