Example #1
0
 //Online users list double click to open private chat
 private void listBox1_DoubleClick(object sender, EventArgs e)
 {
     if (usersList.SelectedItem != null) //Check if the selected online user is null
     {
         //This used to check if the private chat visible.
         //If not new private chat for the specific client will open
         Boolean flag = true;
         //Get index of the selected client
         int userIndex = usersList.SelectedIndex;
         //Get endpoint of a specific client
         string selectUser = endpoints[endpoints.Count - userIndex - 1];
         //check if the private chat all ready open
         foreach (Private_Chat pcUser in pcUsers.Keys)
         {
             if (selectUser.Equals(pcUser.Endpoint))
             {
                 if (pcUser.Visible)
                 {
                     flag           = false;
                     pcUser.Visible = true;
                 }
                 else
                 {
                     pcUsers.Remove(pcUser); //If form not visible remove the form
                 }
                 break;
             }
         }
         //If the private chat not opened. Flag value will be trye.
         if (flag)
         {
             //Finiding specific client details and open a new private chat with the specific selected client
             foreach (string users in onlineUsers.Keys)
             {
                 if (users.Equals(selectUser))
                 {
                     Private_Chat pc = new Private_Chat();
                     pc.ClntName = onlineUsers[selectUser].ToString();
                     pc.Username = username;
                     pc.Endpoint = users;
                     pc.Tcpclnt  = tcpclnt;
                     pcUsers.Add(pc, users);
                     pc.Visible = true;
                     break;
                 }
             }
         }
         else
         {
             MessageBox.Show("Private Chat already opened", "", MessageBoxButtons.OK
                             , MessageBoxIcon.Information);
         }
     }
 }
Example #2
0
        //Open or set received private message to the client private chat window
        private void openPrivateChat(string ip, string user, string msg)
        {
            //Flag used to check if the client already have a private chat. If not open a new private chat
            Boolean flag = true;

            //Check if client having a private chat with the other client already
            foreach (Private_Chat pcUser in pcUsers.Keys)
            {
                if (pcUsers[pcUser].Equals(ip))
                {
                    this.Invoke((MethodInvoker) delegate()
                    {
                        if (pcUser.Visible)
                        {
                            flag = false;
                            pcUser.setStatus(onlineUsers[user] + " : " + msg); //Client available display received message
                        }
                        else
                        {
                            pcUsers.Remove(pcUser); //If private form not visible remove private chat window from the list
                        }
                    });

                    break;
                }
            }
            if (flag)
            {
                this.Invoke((MethodInvoker) delegate()
                {
                    //Open a new private chat
                    Private_Chat pc = new Private_Chat();
                    pc.ClntName     = onlineUsers[user].ToString();
                    pc.Username     = username;
                    pc.Endpoint     = ip;
                    pc.Tcpclnt      = tcpclnt;
                    pcUsers.Add(pc, ip);
                    pc.Visible = true;
                    pc.setStatus(onlineUsers[user] + " : " + msg);
                });
            }
        }