//收到好友发送的聊天信息 public void send_chat_rsp(string[] arr_recv) { int friend_userid = int.Parse(arr_recv[1]); if (map_friendinfo.ContainsKey(friend_userid)) { Frm_chat frm_chat = null; if (map_chatfrm.ContainsKey(friend_userid)) { //如果此好友的聊天窗口已经存在,则不再创建新的聊天窗口 frm_chat = (Frm_chat)map_chatfrm[friend_userid]; } else { //如果此好友的聊天窗口不存在,则创建新的聊天窗口,并加入到聊天窗口map中 frm_chat = new Frm_chat(); frm_chat.Owner = this; map_chatfrm[friend_userid] = (Form)frm_chat; frm_chat.set_friend_info(self_userid, self_name, friend_userid, map_friendinfo[friend_userid].name, map_friendinfo[friend_userid].head); } //添加本次聊天信息到聊天窗口 string str_cur_chat = map_friendinfo[friend_userid].name + " " + DateTime.Now.ToString() + "\n " + arr_recv[2]; frm_chat.recv_chat(str_cur_chat); //如果聊天窗口处于隐藏状态,则添加到头像跳动列表 if (!frm_chat.Visible) { map_beat[friend_userid] = true; } } }
//双击好友头像后,弹出聊天窗口 private void lv_friend_MouseDoubleClick(object sender, MouseEventArgs e) { if (lv_friend.SelectedItems.Count > 0) { int selected_userid = int.Parse(lv_friend.SelectedItems[0].Text); if (map_friendinfo.ContainsKey(selected_userid)) { Frm_chat frm_chat = null; if (map_chatfrm.ContainsKey(selected_userid)) { //如果此好友的聊天窗口已经存在,则不再创建新的聊天窗口 frm_chat = (Frm_chat)map_chatfrm[selected_userid]; } else { //如果此好友的聊天窗口不存在,则创建新的聊天窗口,并加入到聊天窗口map中 frm_chat = new Frm_chat(); frm_chat.Owner = this; map_chatfrm[selected_userid] = (Form)frm_chat; //设置聊天窗口的好友信息 frm_chat.set_friend_info(self_userid, self_name, selected_userid, map_friendinfo[selected_userid].name, map_friendinfo[selected_userid].head); } //显示聊天窗口 frm_chat.Show(); //停止头像跳动 map_beat.Remove(selected_userid); //显示好友头像 if (map_head.ContainsKey(selected_userid) && map_friendinfo.ContainsKey(selected_userid)) { map_head[selected_userid].ImageIndex = map_friendinfo[selected_userid].head - 1; } } } }