Пример #1
0
 private void ChatUnreadMessage_MouseClick(object sender, MouseEventArgs e)
 {
     unreadMessages = 0;
     if (InnerChatContainer.Controls.Count <= 1)
     {
         return;
     }
     InnerChatContainer.ScrollControlIntoView(InnerChatContainer.Controls[InnerChatContainer.Controls.Count - 1]);
     ChatUnreadMessage.Hide();
 }
Пример #2
0
        private void ResizeChat(bool resizeWindow = false)
        {
            if (InnerChatContainer.Controls.Count <= 0)
            {
                return;
            }
            if (CurrentUser == null)
            {
                return;
            }
            if (RecipientUser == null)
            {
                return;
            }

            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(() => { ResizeChat(resizeWindow); }));
                return;
            }

            bool  bottom     = InnerChatContainer.VerticalScroll.Value + InnerChatContainer.Height + 1 >= InnerChatContainer.VerticalScroll.Maximum;
            Point autoScroll = InnerChatContainer.AutoScrollPosition;

            InnerChatContainer.AutoScrollPosition = new Point(0, 0);

            int y = 5;

            foreach (MessageBlock msg in InnerChatContainer.Controls.OfType <MessageBlock>())
            {
                if (msg.Sender != CurrentUser.UserName)
                {
                    msg.Alternate = true;
                }
                else
                {
                    msg.Alternate = false;
                }

                Invoke(new MethodInvoker(() =>
                {
                    msg.MaximumSize = new Size(((InnerChatContainer.Width - 20) / 2) - 20, int.MaxValue);
                    msg.FormatSize();

                    int x = msg.Sender.ToLower() == CurrentUser.UserName.ToLower() ?
                            (InnerChatContainer.Width - msg.Width - 30) : 20;

                    msg.Location = new Point(x, y);
                }));

                y += msg.Height + 10;
            }

            if (bottom || resizeWindow)
            {
                InnerChatContainer.ScrollControlIntoView(InnerChatContainer.Controls[InnerChatContainer.Controls.Count - 1]);
            }
            else
            {
                unreadMessages++;
                ChatUnreadMessage.Text = "You have " + unreadMessages + " unread message" + (unreadMessages > 1 ? "s" : "");
                ChatUnreadMessage.Show();
                InnerChatContainer.AutoScrollPosition = new Point(-autoScroll.X, -autoScroll.Y);
            }

            if (Uploading)
            {
                int maxX   = UploadHiddenItems.Location.X;
                int hidden = 0;
                foreach (UploadPictureBox upBox in UploadContainer.Controls.OfType <UploadPictureBox>())
                {
                    if (upBox.Location.X + upBox.Width >= maxX)
                    {
                        hidden++;
                        upBox.Visible = false;
                    }
                    else if (!upBox.Visible)
                    {
                        upBox.Visible = true;
                    }
                }

                if (hidden == 0)
                {
                    UploadHiddenItems.Visible = false;
                }
                else
                {
                    UploadHiddenItems.Text = "+" + hidden;
                }
            }

            UserTyping.Location = new Point((ChatContainer.Width / 2 - (UserTyping.Width / 2)), UserTyping.Location.Y);
        }