Exemplo n.º 1
0
        private void Control_Click(object sender, EventArgs e)
        {
            Panel pnl;

            ContextMenu cm = (ContextMenu)((MenuItem)sender).Parent;

            pnl = (Panel)cm.SourceControl;

            Panel pnlFriendChat = null;
            int   index         = lstChats.IndexOf(new Chat(client)
            {
                FriendID = pnl.Tag.ToString()
            });
            Chat chat = null;

            if (index != -1)
            {
                foreach (Panel chatPnl in pnlChats.Controls)
                {
                    if (chatPnl.Tag.ToString() == pnl.Tag.ToString())
                    {
                        pnlFriendChat = chatPnl;
                        chat          = lstChats[index];
                    }
                    else
                    {
                        chatPnl.BackColor = Color.FromArgb(0, 10, 20);
                    }
                }
            }
            else
            {
                pnlFriendChat = new Panel()
                {
                    Font      = defaultFont,
                    Name      = "pnlUserInfo",
                    Size      = new System.Drawing.Size(254, 55),
                    TabIndex  = 4,
                    Cursor    = Cursors.Hand,
                    Tag       = pnl.Tag.ToString(),
                    Margin    = new Padding(0),
                    BackColor = Color.FromArgb(0, 10, 20)
                };
                Label lblUserID = new Label
                {
                    ForeColor = Color.FromArgb(187, 188, 182),
                    AutoSize  = true,
                    Font      = defaultFont,
                    Location  = new Point(20, 10),
                    TabIndex  = 3,
                    Text      = pnl.Tag.ToString()
                };

                foreach (Panel chatPnl in pnlChats.Controls)
                {
                    chatPnl.BackColor = Color.FromArgb(0, 10, 20);
                }
                chat = new Chat(client)
                {
                    FriendID = pnl.Tag.ToString()
                };

                lstChats.Add(chat);
                pnlFriendChat.Controls.Add(lblUserID);
                pnlChats.Controls.Add(pnlFriendChat);
                pnlChat.Controls.Add(chat.pnlChat);
            }
            chat.pnlChat.Visible = true;
            chat.pnlChat.BringToFront();
            pnlFriendChat.BackColor = Color.FromArgb(44, 53, 59);
            pnlMessages.Visible     = true;
            pnlMessages.BringToFront();
        }
Exemplo n.º 2
0
        public void getMessage(MessageViewModel msg)
        {
            Chat chat = new Chat(client)
            {
                FriendID = msg.SourceID
            };
            int index = lstChats.IndexOf(chat);

            if (index != -1)
            {
                foreach (Panel chatPnl in pnlChats.Controls)
                {
                    if (chatPnl.Tag.ToString() == lstChats[index].FriendID)
                    {
                        chatPnl.BackColor = Color.FromArgb(44, 53, 59);
                    }
                    else
                    {
                        chatPnl.BackColor = Color.FromArgb(0, 10, 20);
                    }
                }

                for (int i = 0; i < lstChats.Count; i++)
                {
                    if (i != index)
                    {
                        lstChats[i].pnlChat.Visible = false;
                    }
                }
            }
            else
            {
                Panel pnlFriendChat = new Panel()
                {
                    Font      = defaultFont,
                    Name      = "pnlUserInfo",
                    Size      = new System.Drawing.Size(254, 55),
                    TabIndex  = 4,
                    Cursor    = Cursors.Hand,
                    Tag       = msg.SourceID,
                    Margin    = new Padding(0),
                    BackColor = Color.FromArgb(44, 53, 59)
                };
                pnlFriendChat.Click += PnlFriendChat_Click;
                Label lblUserID = new Label
                {
                    ForeColor = Color.FromArgb(187, 188, 182),
                    AutoSize  = true,
                    Font      = defaultFont,
                    Location  = new Point(20, 10),
                    TabIndex  = 3,
                    Text      = msg.SourceID
                };

                foreach (Panel chatPnl in pnlChats.Controls)
                {
                    chatPnl.BackColor = Color.FromArgb(0, 10, 20);
                }
                index = lstChats.Count;
                lstChats.Add(chat);
                pnlFriendChat.Controls.Add(lblUserID);
                pnlChats.Controls.Add(pnlFriendChat);
                pnlChat.Controls.Add(chat.pnlChat);
            }
            lstChats[index].newMessage(msg);
            lstChats[index].pnlChat.Visible = true;
            lstChats[index].pnlChat.BringToFront();
            pnlMessages.Visible = true;
            pnlMessages.BringToFront();
        }