Exemple #1
0
 private void MouseEvent(object sender, MouseEventArgs e)
 {
     if (listOnLine.Visible)
     {
         if (listOnLine.SelectedItems.Count > 0)
         {
             //var txt = listOnLine.SelectedItems[0].Name;
             //// MessageBox.Show(txt);
             var chatName = listOnLine.SelectedItems[0].Text;
             var chatNo   = listOnLine.SelectedItems[0].Name;
             if (!dicChatFrm.Keys.Contains(chatNo))
             {
                 Chat ct = new Chat()
                 {
                     userNo   = this.account,
                     userName = this.uname,
                     chatName = chatName,
                     chatNo   = chatNo,
                 };
                 FrmClientTcp chatClient = new FrmClientTcp(ct, clientSocket);
                 chatClient.Show();
                 chatClient.Closed += (s, args) => this.RemoveFrm(chatNo);
                 dicChatFrm.Add(chatNo, chatClient);
             }
             else
             {
                 var frm = dicChatFrm[chatNo];
                 if (frm.WindowState == FormWindowState.Minimized)
                 {
                     frm.WindowState = FormWindowState.Normal;
                 }
                 frm.Show();
             }
         }
     }
     else
     {
         if (listOffLine.SelectedItems.Count > 0)
         {
             var txt = listOffLine.SelectedItems[0].Text;
             // MessageBox.Show(txt);
         }
     }
 }
Exemple #2
0
        private void ShowMsg(Packet pct)
        {
            var friend = onLineUserList.Where(s => s.userAccount == pct.comeNo).FirstOrDefault();

            if (friend == null)
            {
                friend = offLineUserList.Where(s => s.userAccount == pct.comeNo).FirstOrDefault();
            }
            if (friend != null)
            {
                pct.comeName = friend.userName;
                FrmClientTcp frmtcp = null;
                if (dicChatFrm.Keys.Contains(pct.comeNo))
                {
                    frmtcp = dicChatFrm[pct.comeNo];
                    frmtcp.Invoke(new Action(() =>
                    {
                        if (pct.type == MessageType.Message)
                        {
                            frmtcp.DisplayMessage(pct.comeName, pct.msg);
                            frmtcp.Show();
                        }
                        if (pct.type == MessageType.Shake)
                        {
                            frmtcp.FrmShake();
                            //pct.msg = "发来振动";
                        }
                        if (pct.type == MessageType.Img)
                        {
                            frmtcp.DisplayImg(pct);
                        }
                        //frmtcp.DisplayMessage(pct.comeName, pct.msg);
                        //frmtcp.Show();
                        //if (pct.type == MessageType.Shake)
                        //{
                        //    this.thDataFromServer.sl
                        //    if (frmtcp.WindowState == FormWindowState.Minimized)
                        //    {
                        //        frmtcp.WindowState = FormWindowState.Normal;
                        //    }

                        //}
                    }));
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        Chat ct = new Chat()
                        {
                            userNo   = this.account,
                            userName = this.uname,
                            chatName = pct.comeName,
                            chatNo   = pct.comeNo,
                        };
                        frmtcp         = new FrmClientTcp(ct, clientSocket);
                        frmtcp.Closed += (s, args) => this.RemoveFrm(pct.comeNo);
                        dicChatFrm.Add(pct.comeNo, frmtcp);
                        if (pct.type == MessageType.Message)
                        {
                            frmtcp.DisplayMessage(pct.comeName, pct.msg);
                            frmtcp.Show();
                        }
                        if (pct.type == MessageType.Shake)
                        {
                            frmtcp.FrmShake();
                        }
                        if (pct.type == MessageType.Img)
                        {
                            frmtcp.DisplayImg(pct);
                        }
                    }));
                }
            }
        }