//发送消息 private void button_send_Click(object sender, EventArgs e) { if (!Sock_connected.sock.Connected) { MessageBox.Show("对方已退出聊天窗口,聊天结束。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Sock_connected.Close(); Close(); return; } string text_send = textBox_message.Text; //Sock_connected.Send_message_asy("_m"+my_name+"_"+text_send); Sock_connected.Send_message_NumString_asy(1, my_name + "_" + text_send); add_msg2list("我", text_send, Color.Green); textBox_message.Text = "";//清空消息输入框 }
//发送键按下 private void button_send_Click(object sender, EventArgs e) { string text_send = textBox_message.Text; add_msg2list("我", text_send, Color.Green); if (host_flag) //是房主 { send_msg2all(my_name, text_send, true); } else { if (!host_connectNC.sock.Connected) { MessageBox.Show("群组已解散!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } //向房主发消息不用发名字 host_connectNC.Send_message_NumString_asy(0, text_send); } textBox_message.Text = ""; }