private void listBox_Member_MouseDoubleClick(object sender, MouseEventArgs e) { IPEndPoint ipe = (IPEndPoint)listBox_Member.SelectedItem; client selectitem = new client(); selectitem.Create(ipe); if (localclient.Long_ip == selectitem.Long_ip) { MessageBox.Show("您选择了与自己聊天"); return; } int index = Chatting_List.FindIndex(x => x._client.Long_ip == selectitem.Long_ip); if (index == -1) { Chatting fm2 = new Chatting(); fm2._client.Create(ipe); fm2.fm2 = new From_Chatting(); fm2.fm2.Text = ipe.ToString(); fm2.fm2.ChatWho = ipe; fm2.fm2.Fromclose = new ChildFromClose(Chat_Close); fm2.fm2.Show(); Chatting_List.Add(fm2); } }
public void ChatControl(byte[] pack, IPEndPoint ip_come) { CheckAlive(ip_come); client tem = new client(); tem.Create(ip_come); // 搜索已经开启聊天的表 int index = Chatting_List.FindIndex(x => x._client.Long_ip == tem.Long_ip); if (index == -1) // 新用户 { Chatting fm2 = new Chatting(); fm2._client.Create(ip_come); fm2.fm2 = new From_Chatting(); fm2.fm2.Text = ip_come.ToString(); fm2.fm2.ChatWho = ip_come; fm2.fm2.Fromclose = new ChildFromClose(Chat_Close); fm2.fm2.Show(); Chatting_List.Add(fm2); ShowMessageService sms = new ShowMessageService(fm2.fm2.UpdateLabel); byte[] str = pack.Skip(1).ToArray(); this.BeginInvoke(sms, Encoding.Default.GetString(str)); } else { ShowMessageService sms = new ShowMessageService(Chatting_List[index].fm2.UpdateLabel); byte[] str = pack.Skip(1).ToArray(); this.BeginInvoke(sms, Encoding.Default.GetString(str)); } }