private void customListView1_ScrolledNearStart(object sender, EventArgs e)
        {
            foreach (CustomListViewItem item in customListView1.Controls)
            {
                IChatMessageItem messageItem = item as IChatMessageItem;

                if (messageItem.Message.MessageNumber == 0)
                {
                    return;
                }
                else if (messageItem.Message.MessageNumber > -1)
                {
                    customListView1.InsertItemsAtTop(ConvertToListViewItems(_chat.GetLastMessages(messageItem.Message.MessageNumber, MESSAGE_COUNT_PER_SCROLL), false));
                    return;
                }
            }
        }
        public ChatMessageView(BitChat chat, ChatListItem chatItem)
        {
            InitializeComponent();

            _chat     = chat;
            _chatItem = chatItem;

            _chat.MessageReceived             += chat_MessageReceived;
            _chat.MessageDeliveryNotification += chat_MessageDeliveryNotification;
            _chat.FileAdded  += chat_FileAdded;
            _chat.PeerAdded  += chat_PeerAdded;
            _chat.PeerTyping += chat_PeerTyping;
            _chat.PeerHasRevokedCertificate  += chat_PeerHasRevokedCertificate;
            _chat.PeerSecureChannelException += chat_PeerSecureChannelException;
            _chat.PeerHasChangedCertificate  += chat_PeerHasChangedCertificate;

            this.Title = _chat.NetworkDisplayTitle;

            if (_chat.NetworkType == BitChatCore.Network.BitChatNetworkType.GroupChat)
            {
                _chat.GroupImageChanged += chat_GroupImageChanged;
            }

            //load stored messages
            int totalMessageCount = _chat.GetMessageCount();

            if (totalMessageCount > 0)
            {
                try
                {
                    customListView1.ReplaceItems(ConvertToListViewItems(_chat.GetLastMessages(totalMessageCount, MESSAGE_COUNT_PER_SCROLL), true));
                    customListView1.ScrollToBottom();
                }
                catch
                { }
            }
        }