コード例 #1
0
        //Received UI
        public ChatUI(string message, string date, Image contactPicture, int buffer, EmojiPanel emoji)
        {
            messageTab = new Panel();
            Panel           picturePanel    = new Panel();
            RoundPictureBox picture         = new RoundPictureBox();
            Panel           messageBoxPanel = new Panel();

            messageBox = new MyFixedRichTextBox(true);
            messageBox.setEmojiRef(emoji);//Update richtextbox to have a reference to the emojiPanel
            Label time = new Label();

            messageTab.Controls.Add(messageBoxPanel);
            messageTab.Controls.Add(time);
            messageTab.Controls.Add(picturePanel);
            messageTab.Dock    = DockStyle.Top;
            messageTab.Padding = new Padding(0, buffer, 0, 0);
            messageTab.Size    = new Size(767, 42 + buffer);

            picturePanel.BackColor = Color.White;
            picturePanel.Controls.Add(picture);
            picturePanel.Dock    = DockStyle.Left;
            picturePanel.Padding = new Padding(0, 0, 10, 0);
            picturePanel.Size    = new Size(52, 42);

            picture.BackColor             = Color.Transparent;
            picture.BackgroundImageLayout = ImageLayout.None;
            picture.Dock     = DockStyle.Top;
            picture.Image    = contactPicture;//Properties.Resources.user;
            picture.Size     = new Size(42, 42);
            picture.SizeMode = PictureBoxSizeMode.StretchImage;

            messageBoxPanel.Controls.Add(messageBox);
            messageBoxPanel.BackColor = Color.FromArgb(240, 244, 248);
            messageBoxPanel.ForeColor = Color.FromArgb(43, 43, 48);
            messageBoxPanel.Dock      = DockStyle.Fill;
            messageBoxPanel.Padding   = new Padding(14, 8, 50, 6);

            messageBox.BackColor    = Color.FromArgb(240, 244, 248);
            messageBox.ForeColor    = Color.FromArgb(43, 43, 48);
            messageBox.BorderStyle  = BorderStyle.None;
            messageBox.Dock         = DockStyle.Fill;
            messageBox.Font         = new Font("Segoe UI", 11F);
            messageBox.ReadOnly     = true;
            messageBox.WordWrap     = true;
            messageBox.Multiline    = true;
            messageBox.ScrollBars   = RichTextBoxScrollBars.None;
            messageBox.Text         = message;
            messageBox.GotFocus    += new EventHandler(messageBox_GotFocus);
            messageBox.TextChanged += (sender, e) => messageBox_SizeChanged(messageBox, buffer, messageTab, messageBoxPanel);
            messageBox.Resize      += (sender, e) => messageBox_SizeChanged(messageBox, buffer, messageTab, messageBoxPanel);

            time.ForeColor  = Color.FromArgb(102, 116, 134);
            time.Dock       = DockStyle.Right;
            time.Font       = new Font("Segoe UI", 8F);
            time.ImageAlign = ContentAlignment.TopCenter;
            time.Padding    = new Padding(50, 11, 0, 0);
            time.Size       = new Size(176, 42);
            time.Text       = date;// DateTime.Now.ToString("h:mm tt");
            time.TextAlign  = ContentAlignment.TopCenter;
        }
コード例 #2
0
        private void messageBox_SizeChanged(object sender, int buffer, Panel messageTab, Panel messageBoxPanel)
        {
            MyFixedRichTextBox box = (MyFixedRichTextBox)sender;
            int line = box.GetLineFromCharIndex(box.Text.Length - 1);

            if (messageTab.Height != 42 + buffer + (25 * line))
            {
                messageTab.Height = 42 + buffer + (25 * line);
            }
            if (messageBoxPanel.Height != 42 + (25 * line))
            {
                messageBoxPanel.Height = 42 + (25 * line);
            }
            if (box.Height != 28 + (25 * line))
            {
                box.Height = 28 + (25 * line);
            }
        }
コード例 #3
0
        //Sent UI
        public ChatUI(string message, int buffer, EmojiPanel emoji)
        {
            messageTab = new Panel();
            Panel messageBoxPanel = new Panel();

            messageBox = new MyFixedRichTextBox(true);
            messageBox.setEmojiRef(emoji);//Update richtextbox to have a reference to the emojiPanel
            Label time = new Label();

            messageTab.BackColor = Color.White;
            messageTab.Controls.Add(messageBoxPanel);
            messageTab.Controls.Add(time);
            messageTab.Dock    = DockStyle.Top;
            messageTab.Padding = new Padding(102, buffer, 0, 0);
            messageTab.Size    = new Size(808, 42 + buffer);

            messageBoxPanel.BackColor = Color.FromArgb(199, 237, 252);
            messageBoxPanel.Controls.Add(messageBox);
            messageBoxPanel.Dock    = DockStyle.Fill;
            messageBoxPanel.Padding = new Padding(14, 8, 50, 6);

            messageBox.BackColor    = Color.FromArgb(199, 237, 252);
            messageBox.ForeColor    = Color.FromArgb(43, 43, 48);
            messageBox.BorderStyle  = BorderStyle.None;
            messageBox.Font         = new Font("Segoe UI", 11F);
            messageBox.ReadOnly     = true;
            messageBox.WordWrap     = true;
            messageBox.Multiline    = true;
            messageBox.ScrollBars   = RichTextBoxScrollBars.None;
            messageBox.Text         = message;
            messageBox.Dock         = DockStyle.Fill;
            messageBox.GotFocus    += new EventHandler(messageBox_GotFocus);
            messageBox.TextChanged += (sender, e) => messageBox_SizeChanged(messageBox, buffer, messageTab, messageBoxPanel);
            messageBox.Resize      += (sender, e) => messageBox_SizeChanged(messageBox, buffer, messageTab, messageBoxPanel);

            time.ForeColor = Color.FromArgb(102, 116, 134);
            time.Dock      = DockStyle.Right;
            time.Font      = new Font("Segoe UI", 8F);
            time.Padding   = new Padding(0, 11, 0, 0);
            time.Size      = new Size(126, 42);
            time.Text      = DateTime.Now.ToString("h:mm tt");
            time.TextAlign = ContentAlignment.TopCenter;
        }
コード例 #4
0
        //This funciton is really slow atm, need to decode in order
        public void insertEmoji(MyFixedRichTextBox messageBox)
        {
            List <int>    codeIndex  = new List <int>();
            List <Image>  emojiImage = new List <Image>();
            List <string> codes      = getEmojiCodes();
            List <int>    usedIndex  = new List <int>();

            for (int a = 0; a < codes.Count; a++)
            {
                if (messageBox.Text.Contains(codes[a]))
                {
                    usedIndex.Add(a);
                }
            }

            if (usedIndex.Count > 0)
            {
                for (int a = 0; a < messageBox.Text.Length; a++)
                {
                    for (int b = 0; b < usedIndex.Count; b++)
                    {
                        if (messageBox.Text.Length > a + codes[usedIndex[b]].Length - 1)
                        {
                            if (messageBox.Text.Substring(a, codes[usedIndex[b]].Length) == codes[usedIndex[b]])
                            {
                                messageBox.Text = messageBox.Text.Remove(a, codes[usedIndex[b]].Length);
                                codeIndex.Add(a);
                                emojiImage.Add(getEmojiPics()[usedIndex[b]].Image);
                                a--;
                                break;
                            }
                        }
                    }
                }
            }
            //for(int a = codeIndex.Count - 1; a > -1; a--)
            for (int a = codeIndex.Count - 1; a > -1; a--)
            {
                messageBox.SelectionStart = codeIndex[a];
                messageBox.InsertControl(getEmoji(emojiImage[a], messageBox.BackColor, 25), getEmojiPics().FindIndex(x => x.Image.Equals(emojiImage[a])));
            }
        }
コード例 #5
0
        //Mouse Clicked
        private void tab_MouseClicked(object sender, EventArgs e)
        {
            Panel pan = (Panel)sender;

            if (contactIndex != contacts.Controls.IndexOf(pan))
            {
                if (contactIndex >= 0)
                {
                    Panel controller = (Panel)contacts.Controls[contactIndex];
                    controller.BackColor = Color.FromArgb(240, 244, 248);
                }

                convoPanel.Visible = false;
                msgBox.Enabled     = false;
                msgBox.Enabled     = true;
                contactIndex       = contacts.Controls.IndexOf(pan);
                Contact contact = contactList[contactIndex];

                List <UnreadMessage> unreadMessages = contact.getUnreadMessageList();
                List <Control>       conversationUI = contact.getConversationUI();
                //Check and update all unread messages && Recreate new conversation
                for (int a = 0; a < contact.getUnreadMessageCount(); a++)
                {
                    string message = unreadMessages[a].getMessage();
                    string date    = unreadMessages[a].getDate();
                    if (conversationUI.Count > 0 && conversationUI[conversationUI.Count - 1].Controls[1].Text == date)//Merger
                    {
                        //Convert any emoji codes that might be inside the message
                        MyFixedRichTextBox.AppendText((MyFixedRichTextBox)conversationUI[conversationUI.Count - 1].Controls[0].Controls[0], "\r\n" + message, emoji);
                        contact.updateConversation(conversationUI.Count - 1, conversationUI[conversationUI.Count - 1]);
                    }
                    else
                    {
                        //New Message, so create the buffer first
                        //contact.updateConversation(ChatUI.getPanelBuffer(4));
                        Panel newMessage = new ChatUI("", date, contact.getContactPicture().Image, 4, emoji).getMessageTab();
                        MyFixedRichTextBox.AppendText((MyFixedRichTextBox)newMessage.Controls[0].Controls[0], message, emoji);
                        contact.updateConversation(newMessage);
                    }
                }
                contact.clearUnreadMessages();

                convoPanel.Controls.Clear();
                conversationUI = contact.getConversationUI();
                for (int a = 0; a < conversationUI.Count; a++)
                {
                    convoPanel.Controls.Add(conversationUI[a]);
                    convoPanel.Controls.SetChildIndex(conversationUI[a], 0);
                }
                convoPanel.AutoScrollPosition = new Point(0, convoPanel.VerticalScroll.Maximum);

                //convoBox.Text = contactList[contactIndex].getConversation();
                //convoBox.SelectionStart = convoBox.TextLength;
                //convoBox.ScrollToCaret();
                string name = contact.getPacket().getUsername();
                if (contact.getContactName().Text != name)
                {
                    contact.getContactName().Text = name;
                }

                //Add the new contact to the current contact panel
                if (currentContact.Controls.Count == 0)
                {
                    currentContactUI = new ContactUI(contact.getPacket().getUsername(), contact.getPacket().getContactPicture(), false);
                    currentContact.Controls.Add(currentContactUI.getContactUITab());
                    currentContact.Controls.SetChildIndex(currentContactUI.getContactUITab(), 0);
                    //Might add user controls below for when you click the current contact tab
                }
                else
                {
                    //Update the picture and name for the current contact tab
                    currentContactUI.getContactUIName().Text     = contact.getPacket().getUsername();
                    currentContactUI.getContactUIPicture().Image = contact.getContactPicture().Image;
                }

                //Handle msgBox text -- might have a message previously typed but not sent?
                if (contact.getCurrentMessage() == "")
                {
                    msgBox.ForeColor = Color.FromArgb(102, 116, 134);
                    msgBox.Font      = new Font("Segoe UI", 9.5F);
                    msgBox.Text      = "Type a message here";
                }
                else
                {
                    msgBox.ForeColor = Color.FromArgb(43, 43, 48);
                    msgBox.Font      = new Font("Segoe UI", 10.15F);
                    msgBox.Text      = contact.getCurrentMessage();
                    emoji.insertEmoji(msgBox);
                }
                convoPanel.Visible = true;
            }
        }
コード例 #6
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            //We have a name selected
            if (contactIndex >= 0)
            {
                string message = decode(msgBox.Text);

                Contact contact = contactList[contactIndex];
                contact.saveCurrentMessage("");
                msgBox.Focus();//FOCUS NEEDS TO HAPPEN FIRST
                msgBox.Clear();

                if (packetSupport())
                {
                    //Send a Message Packet To Server, need to update friends convoBox and conversation string
                    ClientPacket  packet        = new ClientPacket(profile.getUsername(), profile.getIP(), message, contact.getPacket().getUsername(), contact.getPacket().getClientIP());
                    IFormatter    formatter     = new BinaryFormatter(); //the formatter that will serialize my object on my stream
                    NetworkStream networkStream = new NetworkStream(clientSocket);
                    formatter.Serialize(networkStream, packet);          //the serialization process
                    networkStream.Close();
                }
                else
                {
                    clientSocket.Send(Encoding.ASCII.GetBytes(message));
                }

                //Append new message to our convoBox
                //appendToConvoBox("You: " + message);

                //Save our msg to our conversation string
                //contact.setConversation(convoBox.Text);

                int            buffer = 4;
                List <Control> currentConversation = contact.getConversationUI();
                if (convoPanel.Controls.Count > 0)
                {
                    //Check if last message was yours
                    if (convoPanel.Controls[0].Controls[0].BackColor == Color.FromArgb(199, 237, 252))
                    {
                        //Check if your within time frame to merge messages
                        if (convoPanel.Controls[0].Controls[1].Text == DateTime.Now.ToString("h:mm tt"))
                        {
                            MyFixedRichTextBox.AppendText((MyFixedRichTextBox)convoPanel.Controls[0].Controls[0].Controls[0], "\r\n" + message, emoji);
                            convoPanel.AutoScrollPosition = new Point(0, convoPanel.VerticalScroll.Maximum);
                            //Update new message to the conversationUI
                            contact.updateConversation(currentConversation.Count - 1, convoPanel.Controls[0]);
                            return;
                        }
                        else
                        {
                            //convoPanel.Visible = false;
                            //not within time frame so go ahead and buffer new space

                            /* Panel buffer = ChatUI.getPanelBuffer(4);
                             * convoPanel.Controls.Add(buffer);
                             * convoPanel.Controls.SetChildIndex(buffer, 0);
                             * contact.updateConversation(buffer);*/
                        }
                    }
                    else
                    {
                        buffer = 14;
                        //convoPanel.Visible = false;
                        //Message was not yours, so append space

                        /*Panel buffer = ChatUI.getPanelBuffer(14);
                         * convoPanel.Controls.Add(buffer);
                         * convoPanel.Controls.SetChildIndex(buffer, 0);
                         * contact.updateConversation(buffer);*/
                    }
                }

                //Append new message to our convoBox
                ChatUI             msg        = new ChatUI(message, buffer, emoji);
                Panel              messageTab = msg.getMessageTab();
                MyFixedRichTextBox messageBox = msg.getMessageBox();
                emoji.insertEmoji(messageBox);
                contact.updateConversation(messageTab);
                convoPanel.Controls.Add(messageTab);
                convoPanel.Controls.SetChildIndex(messageTab, 0);
                convoPanel.AutoScrollPosition = new Point(0, convoPanel.VerticalScroll.Maximum);
                //convoPanel.Visible = true;
            }
        }
コード例 #7
0
        private void receiveMessage(int index, string message)
        {
            contacts.Invoke(new MethodInvoker(delegate
            {
                Contact contact = contactList[index];
                //Notify you that you got a message
                //contactList[index].updateConversation(message);
                if (contactIndex != index)
                {
                    //Reset Friend Name
                    contact.getContactName().Text = contact.getPacket().getUsername();
                    contact.newUnreadMessage(message, DateTime.Now.ToString("h:mm tt"));
                    contact.getContactName().Text += " (" + contact.getUnreadMessageCount().ToString() + ")";
                }
                else
                {
                    convoPanel.Invoke(new MethodInvoker(delegate
                    {
                        int buffer = 4;
                        List <Control> currentConversation = contact.getConversationUI();
                        if (convoPanel.Controls.Count > 0)
                        {
                            //Check if last message was not yours
                            if (convoPanel.Controls[0].Controls[0].BackColor == Color.FromArgb(240, 244, 248))
                            {
                                //Check if your within time frame to merge received messages
                                if (convoPanel.Controls[0].Controls[1].Text == DateTime.Now.ToString("h:mm tt"))
                                {
                                    MyFixedRichTextBox.AppendText((MyFixedRichTextBox)convoPanel.Controls[0].Controls[0].Controls[0], "\r\n" + message, emoji);
                                    convoPanel.AutoScrollPosition = new Point(0, convoPanel.VerticalScroll.Maximum);
                                    //Update new message to the conversationUI
                                    contact.updateConversation(currentConversation.Count - 1, convoPanel.Controls[0]);
                                    return;
                                }
                                else
                                {
                                    //not within time frame so go ahead and buffer new space

                                    /*Panel buffer = ChatUI.getPanelBuffer(4);
                                     * contact.updateConversation(buffer);
                                     * convoPanel.Controls.Add(buffer);
                                     * convoPanel.Controls.SetChildIndex(buffer, 0);*/
                                }
                            }
                            else
                            {
                                //Message was yours, so append space
                                buffer = 14;

                                /*Panel buffer = ChatUI.getPanelBuffer(14);
                                 * contact.updateConversation(buffer);
                                 * convoPanel.Controls.Add(buffer);
                                 * convoPanel.Controls.SetChildIndex(buffer, 0);*/
                            }
                        }

                        //Append new message to your convoBox
                        ChatUI msg       = new ChatUI(message, DateTime.Now.ToString("h:mm tt"), contact.getContactPicture().Image, buffer, emoji);
                        Panel messageTab = msg.getMessageTab();
                        MyFixedRichTextBox messageBox = msg.getMessageBox();
                        emoji.insertEmoji(messageBox);
                        contact.updateConversation(messageTab);
                        convoPanel.Controls.Add(messageTab);
                        convoPanel.Controls.SetChildIndex(messageTab, 0);
                        convoPanel.AutoScrollPosition = new Point(0, convoPanel.VerticalScroll.Maximum);

                        //convoBox.Text = contactList[index].getConversation();
                        //convoBox.SelectionStart = convoBox.TextLength;
                        //convoBox.ScrollToCaret();
                    }));
                }
            }));
        }
コード例 #8
0
 private void messageBox_GotFocus(object sender, EventArgs e)
 {
     MyFixedRichTextBox box = (MyFixedRichTextBox)sender;
 }